-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 Float32/16 raised to integer typemin #57488
base: master
Are you sure you want to change the base?
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.
Thanks for working on this! You picked a great first issue to contribute based on.
This looks like a functional fix, but I think it might be better to use the same approach that #53967 adds where we use a floating point algorithm for large powers (especially since it would turn this PR into a performance improvement rather than a regression. Specifically, I think the following would work well. (testing now)
|
It does look like a performance improvement (once you get |
Although I don't think this PR is a regression. It runs the same code that it always ran for cases except typemin, which previously crashed. |
I meant performance regression. This code is pretty fast to the point that extra branches can have a significant speed impact. This way the branch is still there, but it is providing a speedup for lots of large powers as well. |
Fixes #57464
The code for
x^n
wherex::Float32
andn::Int
previously failed forFloat32(1.1)^typemin(Int)
because it would reduce the problem toinv(x)^-n
. That works fine unlessn
istypemin
, in which casen==-n
.This PR makes a special case for
n==typemin
to effectively compute(x^(n/2))^2
. Just in casen
is also odd, we dox^cld(n,2) * x^fld(n,2)
.