Skip to content

Commit

Permalink
Improve type stability of sqrt(::Complex)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Jun 20, 2024
1 parent 4d0149d commit 510e0ec
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,13 @@ function robust_cinv(c::Float64, d::Float64)
end

function ssqs(x::T, y::T) where T<:Real
k::Int = 0
k = 0
ρ = x*x + y*y
if !isfinite(ρ) && (isinf(x) || isinf(y))
ρ = convert(T, Inf)
elseif isinf(ρ) ||==0 && (x!=0 || y!=0)) || ρ<nextfloat(zero(T))/(2*eps(T)^2)
m::T = max(abs(x), abs(y))
k = m==0 ? m : exponent(m)
k = m==0 ? k : exponent(m)
xk, yk = ldexp(x,-k), ldexp(y,-k)
ρ = xk*xk + yk*yk
end
Expand All @@ -533,7 +533,7 @@ function sqrt(z::Complex)
if x==y==0
return Complex(zero(x),y)
end
ρ, k::Int = ssqs(x, y)
ρ, k = ssqs(x, y)
if isfinite(x) ρ=ldexp(abs(x),-k)+sqrt(ρ) end
if isodd(k)
k = div(k-1,2)
Expand Down

0 comments on commit 510e0ec

Please sign in to comment.