-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Clean up updated hypot function #33224
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
Conversation
base/math.jl
Outdated
| hypot(x::Complex, y::Complex) = hypot(promote(abs(x),abs(y))...) | ||
| hypot(x::Integer, y::Integer) = hypot(promote(float(x), float(y))...) | ||
| hypot(x::Complex, y::Complex) = hypot(abs(x), abs(y)) | ||
| hypot(x::Integer, y::Integer) = hypot(float(x), float(y)) |
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 think we should actually have hypot(x::T, y::T) where {T<:Number} = hypot(float(x), float(y) and remove the Integer method case.
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.
Won't that break bigfloats et. al?
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.
No it won't actually. hypot has specialized methods in MPFR.
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.
To me this still feels fishy as it means hypot will convert custom number types into floats if they don't specifically define a hypot function.
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.
We already define mathfunction(x::Real) = mathfunction(float(x)) for numerous elementary math functions, such as exp.
Actually, I purposely deferred that to someone else because of my previously demonstrated unfamiliarity with git (I commented on that somewhere in the original thread). I didn't want to make a mess out of it and waste everyone's time. But your point is excellent, the old code should come out. |
|
|
@cfborges Got it, thanks for the clarification. |
It should extend to any floating point system that uses round to nearest. The only things that really depend on the IEEE formats are the parts that prevent overflow/underflow. If someone has an abstract FPS that does something weird (like variable length significands) then it would have to be analyzed further to verify the accuracy. But at worst it would still be better than the previously existing hypot. |
|
Thanks for the review @stevengj . Fixed up the latest commit to change it to This should we good to go now. |
|
good to merge? |
@cfborges Looks like you forgot to delete the existing code (ref #31922)