Skip to content
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

add hypot fallback for 2 Numbers of the same type #34316

Merged
merged 1 commit into from
Jan 13, 2020
Merged

Conversation

JeffBezanson
Copy link
Member

#33224 broke hypot with Unitful.jl. There used to be a method for this. The weird thing is, in the current state it works if you pass 3 arguments to hypot but not 2, so we should probably add this.

@JeffBezanson JeffBezanson added maths Mathematical functions backport 1.4 labels Jan 8, 2020
@KristofferC
Copy link
Member

Seems like this is causing some subtyping crash when creating the sysimage?

@KristofferC KristofferC mentioned this pull request Jan 9, 2020
28 tasks
base/math.jl Outdated
@@ -613,6 +613,7 @@ julia> hypot(3, 4im)
hypot(x::Number, y::Number) = hypot(promote(x, y)...)
hypot(x::Complex, y::Complex) = hypot(abs(x), abs(y))
hypot(x::T, y::T) where {T<:Real} = hypot(float(x), float(y))
hypot(x::T, y::T) where {T<:Number} = sqrt(abs2(x) + abs2(y))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this overflow/underflow, which hypot should not do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least use something like abs(x) * sqrt (1 + (y/x)^2).

@ViralBShah
Copy link
Member

Probably not worth holding up the PR.

@jebej
Copy link
Contributor

jebej commented Jan 9, 2020

Why not just revert that PR and keep the old method for non-AbstractFloats?

@JeffBezanson
Copy link
Member Author

There already is a method for two Reals and two Complexes. So this would only apply to non-Real, non-Complex Numbers, so potentially somewhat exotic types that might not support all operations.

@KristofferC KristofferC merged commit ade4713 into master Jan 13, 2020
@KristofferC KristofferC deleted the jb/hypotfallback branch January 13, 2020 12:50
KristofferC pushed a commit that referenced this pull request Jan 13, 2020
KristofferC pushed a commit that referenced this pull request Jan 15, 2020
KristofferC pushed a commit that referenced this pull request Jan 17, 2020
JeffBezanson pushed a commit that referenced this pull request Feb 21, 2020
Fix hypot with both arguments 0

Remove hypot from Furlongs in order to test the defined fallback
KristofferC pushed a commit that referenced this pull request Feb 21, 2020
Fix hypot with both arguments 0

Remove hypot from Furlongs in order to test the defined fallback

(cherry picked from commit 8e3aa66)
@KristofferC KristofferC mentioned this pull request Feb 21, 2020
26 tasks
birm pushed a commit to birm/julia that referenced this pull request Feb 22, 2020
Fix hypot with both arguments 0

Remove hypot from Furlongs in order to test the defined fallback
KristofferC pushed a commit that referenced this pull request Apr 11, 2020
Fix hypot with both arguments 0

Remove hypot from Furlongs in order to test the defined fallback
BioTurboNick pushed a commit to BioTurboNick/julia that referenced this pull request Apr 13, 2020
BioTurboNick pushed a commit to BioTurboNick/julia that referenced this pull request Apr 13, 2020
Fix hypot with both arguments 0

Remove hypot from Furlongs in order to test the defined fallback

(cherry picked from commit 8e3aa66)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants