-
Notifications
You must be signed in to change notification settings - Fork 226
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
Improve NAN handling in ccmath #912
Conversation
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.
For the hypot()
, log()
, and sqrt()
functions, shouldn't parameters with values of negative infinity result in NaN instead of negative infinity?
E.g. sqrt(-∞) = nan
rather than -∞
.
I know this behavior remains unchanged in this PR, but thought this might be an opportune time to fix.
The language specification is +- infinity returns +- infinity. Since we fallback to the STL at runtime I didn't want the edge case handling to differ based on context. |
C99 at least specifies that sqrt of a negative number is a domain error and yields a NaN, as things stand runtime sqrt(-INF) returns NaN and constexpr sqrt(-INF) returns +INF which looks just plain wrong? |
Ok for |
According to https://en.cppreference.com/w/c/numeric/math/logb
I haven't tested it, but inspecting the code it appears that for the
Shouldn't it return |
Yes; the change is wrong. |
@pulver Can you do one last dummy check for me? I think this is good now and addresses your |
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.
For hypot()
, it looks like
hypot(-∞,1) = -∞
but should return +∞. Same when x and y are swapped, based on hypot:
if one of the arguments is ±∞, hypot(x,y) returns +∞ even if the other argument is NaN
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
No description provided.