-
-
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
Improve exponent function #19512
Improve exponent function #19512
Conversation
What about changing this function to behave as follows (i.e. like ilog2, under certain error flag) and thus things like this actually work
|
the behavior for inf and nan seem dangerous to me, couldn't that cause all sorts of corruption? |
Which are you referring to? |
x = ±Inf returns typemax(Int) |
Perhaps this should be a separate issue as it is independent of the PR, which just improves the current behavior. |
xs = reinterpret(Unsigned, x) & ~sign_mask(T) | ||
xs >= exponent_mask(T) && return throw(DomainError()) # NaN or Inf | ||
k = Int(xs >> significand_bits(T)) | ||
if xs <= (~exponent_mask(T) & ~sign_mask(T)) # x is subnormal |
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.
Would it be better to just do if k == 0
? (comparisons vs values that are representable by Int32
can sometimes be faster)
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.
yea here and for frexp is doesn't matter, I chose consistency with the significand function. See #19492
If you prefer I can change.
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.
Ok I made the chnage here and to frexp
@nanosoldier |
Your benchmark job has completed - no performance regressions were detected. A full report can be found here. cc @jrevels |
thanks! |
Remove unnecessary branch/better perf