Skip to content

Commit 707616d

Browse files
musmKristofferC
authored andcommitted
Clean up updated hypot function (#33224)
* Clean up updated hypot function * f * fixup * fixup * Update math.jl
1 parent ed3aefe commit 707616d

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

base/math.jl

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,12 @@ julia> hypot(3, 4im)
547547
```
548548
"""
549549
hypot(x::Number, y::Number) = hypot(promote(x, y)...)
550-
hypot(x::Complex, y::Complex) = hypot(promote(abs(x),abs(y))...)
551-
hypot(x::Integer, y::Integer) = hypot(promote(float(x), float(y))...)
552-
function hypot(x::T,y::T) where T<:AbstractFloat
550+
hypot(x::Complex, y::Complex) = hypot(abs(x), abs(y))
551+
hypot(x::T, y::T) where {T<:Real} = hypot(float(x), float(y))
552+
function hypot(x::T, y::T) where T<:AbstractFloat
553553
#Return Inf if either or both imputs is Inf (Compliance with IEEE754)
554554
if isinf(x) || isinf(y)
555-
return convert(T,Inf)
555+
return T(Inf)
556556
end
557557

558558
# Order the operands
@@ -594,31 +594,7 @@ function hypot(x::T,y::T) where T<:AbstractFloat
594594
h -= muladd(delta,delta,muladd(ay,(4*delta-ay),2*delta*(ax-2*ay)))/(2*h)
595595
end
596596
end
597-
h*scale
598-
end
599-
function hypot(x::T, y::T) where T<:Number
600-
ax = abs(x)
601-
ay = abs(y)
602-
if ax < ay
603-
ax, ay = ay, ax
604-
end
605-
if iszero(ax)
606-
r = ay / oneunit(ax)
607-
else
608-
r = ay / ax
609-
end
610-
611-
rr = ax * sqrt(1 + r * r)
612-
613-
# Use type of rr to make sure that return type is the same for
614-
# all branches
615-
if isnan(r)
616-
isinf(ax) && return oftype(rr, Inf)
617-
isinf(ay) && return oftype(rr, Inf)
618-
return oftype(rr, r)
619-
else
620-
return rr
621-
end
597+
return h*scale
622598
end
623599

624600
"""

0 commit comments

Comments
 (0)