-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fmin
/fmax
functions to math.h
#303
Conversation
mos-platform/common/c/math.cc
Outdated
@@ -0,0 +1,22 @@ | |||
#include <math.h> | |||
|
|||
template <typename T> static inline bool _is_nan(const T x) { return x != x; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May as well actually implement the macro in <math.h>
:
#define isnan(arg) __builtin_isfpclass(arg, __FPCLASS_SNAN | __FPCLASS_QNAN)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or use the existing __builtin_isnan
over __builtin_isfpclass
? I just noticed that std::numeric_limits<float>::has_quiet_NaN == false
and NAN
is not defined. Is nan at all supported?
Update: also std::numeric_limits<float>::has_infinity == false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I now notice that __builtin_fmin
and __builtin_fmax
along with several other math functions are already defined and seem to be correct. Perhaps better to use these? Are these covered by existing tests in the separate test suite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good point. __builtin_isnan
lowers to the same thing and is clearer.
By contrast, __builtin_fmin
doesn't help us; it lowers to a compiler intrinsic that most naturally lowers to a call to fmin
. By comparison, __builtin_isnan
lowers to a call to __unordsf2
in compiler_rt
, plus a bit of additional logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This adds min and max functions for
float
anddouble
.Closes #299.