-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix rem2pi for NaN #36420
Fix rem2pi for NaN #36420
Conversation
@simeonschaub can you please review it? |
isnan(x) && return NaN | ||
|
||
abs(x) < pi && return 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.
I guess this can be optimized:
isnan(x) && return NaN | |
abs(x) < pi && return x | |
abs(x) >= pi || return 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.
@kimikage Yes. but won't it make it hard to understand and debug later?
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.
That's right. However, for such low-level functions, I prefer the speed. Is it not enough to just add comments into the source?
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.
Worth checking if LLVM figures that out and eliminates the isnan
check.
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.
It seems like LLVM with optimize=true
can't eliminate the fcmp ord double %0, 0.000000e+00
instruction and extra branch from isnan
here. So I think it makes sense to use >=
here to replace the isnan
check and just add an explanatory comment about the NaN
case.
what's the performance impact of this pr? |
About 5% according to
Unless you have smarter ways to deal with non-finite values, this seems a decent trade-off. @JeffreySarnoff just reported on Slack that also
|
removing back-port labels since #46163 is a more complete fix. |
Pretty sure you need both to make the other patch apply cleanly (and avoid manual work). |
Fix for #32888
This will also fix the
mod2pi
.There was a discussion that Domain Error should be thrown or
NaN
should be returned. To be consistent withrem
I returnedNaN