Bound function also bounds NaN (#3118)

* 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>
This commit is contained in:
Ewoud Smeur
2023-09-30 13:04:53 +02:00
committed by GitHub
parent ae1f8ed350
commit 92f467f8cc
+2 -1
View File
@@ -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))) \