Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faster hypot for Float32 and Float16 #42122

Merged
merged 6 commits into from
Nov 10, 2021
Merged
Changes from 5 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
9 changes: 8 additions & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,14 @@ 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)
_x, _y = Float64(x), Float64(y)
return Float32(sqrt(muladd(_x, _x, _y*_y)))
end
@inline function _hypot(x::Float16, y::Float16)
_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