-
-
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
Vararg version of hypot does overflow and underflow on master #27141
Comments
Maybe just define: hypot(x::Number...) = vecnorm(x) |
@stevengj I think the problem is that One alternative would be hypot(x,y,z...) = hypot(hypot(x,y), z...) |
That would be a performance trap, in that it would be much slower than expected. We can also just reimplement the relevant part of vecnorm: it doesn’t take more than a few lines to do the right thing. |
The following cases give even worse failures due to integer wraparound: julia> i = typemax(Int)
9223372036854775807
julia> hypot(i,i,i) # the result is √3 !!
1.7320508075688772
julia> i*√3
1.5975348984942514e19
julia> hypot(10^17, 10^17, 10^17) # 3*abs2(10^17) is negative!
ERROR: DomainError with -6.437707461859213e18: There should definitely be a test for the |
Fixes JuliaLang#27141: The previous code led to under/overflow.
Fixes JuliaLang#27141: The previous code led to under/overflow.
Fixes #27141: The previous code led to under/overflow. Co-authored-by: Jorge Fernandez-de-Cossio-Diaz <j.cossio.diaz@gmail.com>
The point of the
hypot
function is to avoid underflow and overflow, however the implementation of the vararg method introduced with PR #25571 defeats this purpose:Instead in Julia 0.6 it gives the correct result:
Edit: I've just seen this was already pointed out in #25571 (comment)
The text was updated successfully, but these errors were encountered: