diff --git a/base/math.jl b/base/math.jl index 3857b1b1e8c10..b972403381d2b 100644 --- a/base/math.jl +++ b/base/math.jl @@ -696,7 +696,20 @@ function _hypot(x, y) end return h*scale*oneunit(axu) end -_hypot(x::Float16, y::Float16) = Float16(_hypot(Float32(x), Float32(y))) +@inline function _hypot(x::Float32, y::Float32) + if isinf(x) || isinf(y) + return Inf32 + end + _x, _y = Float64(x), Float64(y) + return Float32(sqrt(muladd(_x, _x, _y*_y))) +end +@inline function _hypot(x::Float16, y::Float16) + if isinf(x) || isinf(y) + return Inf16 + end + _x, _y = Float32(x), Float32(y) + return Float16(sqrt(muladd(_x, _x, _y*_y))) +end _hypot(x::ComplexF16, y::ComplexF16) = Float16(_hypot(ComplexF32(x), ComplexF32(y))) function _hypot(x...)