Skip to content
Merged
Changes from 3 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
13 changes: 12 additions & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ _hypot(x::ComplexF16, y::ComplexF16) = Float16(_hypot(ComplexF32(x), ComplexF32(

function _hypot(x::NTuple{N,<:Number}) where {N}
maxabs = maximum(abs, x)
if isnan(maxabs) && any(isinf, x)
if any(isinf, x)
Comment thread
mikmoore marked this conversation as resolved.
Outdated
return typeof(maxabs)(Inf)
elseif (iszero(maxabs) || isinf(maxabs))
return maxabs
Expand All @@ -841,6 +841,17 @@ function _hypot(x::NTuple{N,<:Number}) where {N}
end
end

function _hypot(x::NTuple{N,T}) where {N,T<:IEEEFloat}
infT = convert(T, Inf)
x = abs.(x) # doesn't change result but enables computational shortcuts
any(==(infT), x) && return infT # return Inf even if an argument is NaN
Comment thread
mikmoore marked this conversation as resolved.
maxabs = reinterpret(T, maximum(z -> reinterpret(Signed, z), x)) # for abs(::IEEEFloat) values, a ::BitInteger cast does not change the result
iszero(maxabs) && return maxabs
y = abs2.(x ./ maxabs)
a2 = @fastmath reduce(+, y) # allow sum to be reordered
return sqrt(a2) * maxabs
end

atan(y::Real, x::Real) = atan(promote(float(y),float(x))...)
atan(y::T, x::T) where {T<:AbstractFloat} = Base.no_op_err("atan", T)

Expand Down