Skip to content

Commit

Permalink
faster hypot for Float32 and Float16 (JuliaLang#42122)
Browse files Browse the repository at this point in the history
* faster hypot for Float32 and Float16
  • Loading branch information
Moelf authored and LilithHafner committed Mar 8, 2022
1 parent 2b01c77 commit 6f0253a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,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...)
Expand Down

0 comments on commit 6f0253a

Please sign in to comment.