diff --git a/sw/include/std.h b/sw/include/std.h index 3b4f802cfc..30174444ac 100644 --- a/sw/include/std.h +++ b/sw/include/std.h @@ -135,8 +135,9 @@ typedef uint8_t unit_t; #define BoundUpper(_x, _max) { if (_x > (_max)) _x = (_max);} +// Note: the bound function will bound NaN to min as any comparison that contains NaN is false. +#define Bound(_x, _min, _max) { if (!(_x > (_min))) _x = (_min); else if (!(_x < (_max))) _x = (_max); } -#define Bound(_x, _min, _max) { if (_x > (_max)) _x = (_max); else if (_x < (_min)) _x = (_min); } #define BoundInverted(_x, _min, _max) { \ if ((_x < (_min)) && (_x > (_max))) { \ if (abs(_x - (_min)) < abs(_x - (_max))) \