Skip to content

Commit

Permalink
Bound function also bounds NaN (#3118)
Browse files Browse the repository at this point in the history
* Bound function also bounds nan

* Update comment

Co-authored-by: Christophe De Wagter <dewagter@gmail.com>

* Bound defaults to min in case of NaN

---------

Co-authored-by: Christophe De Wagter <dewagter@gmail.com>
  • Loading branch information
EwoudSmeur and dewagter committed Sep 30, 2023
1 parent ae1f8ed commit 92f467f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sw/include/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))) \
Expand Down

0 comments on commit 92f467f

Please sign in to comment.