Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 5 additions & 29 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,12 @@ julia> hypot(3, 4im)
```
"""
hypot(x::Number, y::Number) = hypot(promote(x, y)...)
hypot(x::Complex, y::Complex) = hypot(promote(abs(x),abs(y))...)
hypot(x::Integer, y::Integer) = hypot(promote(float(x), float(y))...)
function hypot(x::T,y::T) where T<:AbstractFloat
hypot(x::Complex, y::Complex) = hypot(abs(x), abs(y))
hypot(x::T, y::T) where {T<:Real} = hypot(float(x), float(y))
function hypot(x::T, y::T) where T<:AbstractFloat
#Return Inf if either or both imputs is Inf (Compliance with IEEE754)
if isinf(x) || isinf(y)
return convert(T,Inf)
return T(Inf)
end

# Order the operands
Expand Down Expand Up @@ -594,31 +594,7 @@ function hypot(x::T,y::T) where T<:AbstractFloat
h -= muladd(delta,delta,muladd(ay,(4*delta-ay),2*delta*(ax-2*ay)))/(2*h)
end
end
h*scale
end
function hypot(x::T, y::T) where T<:Number
ax = abs(x)
ay = abs(y)
if ax < ay
ax, ay = ay, ax
end
if iszero(ax)
r = ay / oneunit(ax)
else
r = ay / ax
end

rr = ax * sqrt(1 + r * r)

# Use type of rr to make sure that return type is the same for
# all branches
if isnan(r)
isinf(ax) && return oftype(rr, Inf)
isinf(ay) && return oftype(rr, Inf)
return oftype(rr, r)
else
return rr
end
return h*scale
end

"""
Expand Down