diff --git a/base/math.jl b/base/math.jl index 981f152ed383d..462e82c8ab443 100644 --- a/base/math.jl +++ b/base/math.jl @@ -702,6 +702,9 @@ function _hypot(x, y) end return h*scale*oneunit(axu) end +_hypot(x::Float16, y::Float16) = Float16(_hypot(Float32(x), Float32(y))) +_hypot(x::ComplexF16, y::ComplexF16) = Float16(_hypot(ComplexF32(x), ComplexF32(y))) + function _hypot(x...) maxabs = maximum(abs, x) if isnan(maxabs) && any(isinf, x) diff --git a/test/math.jl b/test/math.jl index 21f3f34204500..bfe584ed5d340 100644 --- a/test/math.jl +++ b/test/math.jl @@ -1193,6 +1193,10 @@ end @test hypot(x, x*f) ≈ x * hypot(one(f), f) rtol=eps(T) @test hypot(x, x*f, x*f) ≈ x * hypot(one(f), f, f) rtol=eps(T) end + let x = floatmax(T)/2 + @test (@inferred hypot(x, x/4)) ≈ x * sqrt(17/BigFloat(16)) + @test (@inferred hypot(x, x/4, x/4)) ≈ x * sqrt(9/BigFloat(8)) + end end # hypot on Complex returns Real @test (@inferred hypot(3, 4im)) === 5.0