Skip to content

Commit 4f43007

Browse files
committed
Merge pull request #7436 from JuliaLang/sjk/type_stable_complex
Fix type stability of some operators on Complex32
2 parents 19582f7 + 458772e commit 4f43007

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

base/complex.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,12 @@ end
542542
function asin(z::Complex)
543543
zr, zi = reim(z)
544544
if isinf(zr) && isinf(zi)
545-
return Complex(copysign(pi/4, zr),zi)
545+
return Complex(copysign(oftype(zr, pi/4), zr),zi)
546546
elseif isnan(zi) && isinf(zr)
547547
return Complex(zi, oftype(zr, Inf))
548548
end
549549
ξ = zr == 0 ? zr :
550-
!isfinite(zr) ? pi/2*sign(zr) :
550+
!isfinite(zr) ? oftype(zr, pi/2)*sign(zr) :
551551
atan2(zr, real(sqrt(1-z)*sqrt(1+z)))
552552
η = asinh(copysign(imag(sqrt(conj(1-z))*sqrt(1+z)), imag(z)))
553553
Complex(ξ,η)
@@ -560,18 +560,18 @@ function acos{T<:FloatingPoint}(z::Complex{T})
560560
else return Complex(zr, zr) end
561561
elseif isnan(zi)
562562
if isinf(zr) return Complex(zi, abs(zr))
563-
elseif zr==0 return Complex(pi/2, zi)
563+
elseif zr==0 return Complex(oftype(zr, pi/2), zi)
564564
else return Complex(zi, zi) end
565565
elseif zr==zi==0
566-
return Complex(pi/2, -zi)
566+
return Complex(oftype(zr, pi/2), -zi)
567567
elseif zr==Inf && zi===0.0
568568
return Complex(zi, -zr)
569569
elseif zr==-Inf && zi===-0.0
570570
return Complex(oftype(zi, pi), -zr)
571571
end
572572
ξ = 2*atan2(real(sqrt(1-z)), real(sqrt(1+z)))
573573
η = asinh(imag(sqrt(conj(1+z))*sqrt(1-z)))
574-
if isinf(zr) && isinf(zi) ξ -= pi/4 * sign(zr) end
574+
if isinf(zr) && isinf(zi) ξ -= oftype(η, pi/4) * sign(zr) end
575575
Complex(ξ,η)
576576
end
577577
acos(z::Complex) = acos(float(z))
@@ -629,12 +629,12 @@ function acosh(z::Complex)
629629
return Complex(oftype(zr, NaN), oftype(zi, NaN))
630630
end
631631
elseif zr==-Inf && zi===-0.0 #Edge case is wrong - WHY?
632-
return Complex(Inf, -pi)
632+
return Complex(inf(zr), oftype(zi, -pi))
633633
end
634634
ξ = asinh(real(sqrt(conj(z-1))*sqrt(z+1)))
635635
η = 2atan2(imag(sqrt(z-1)),real(sqrt(z+1)))
636636
if isinf(zr) && isinf(zi)
637-
η -= pi/4 * sign(zi) * sign(zr)
637+
η -= oftype(η, pi/4) * sign(zi) * sign(zr)
638638
end
639639
Complex(ξ, η)
640640
end
@@ -655,17 +655,17 @@ function atanh{T<:FloatingPoint}(z::Complex{T})
655655
end
656656
end
657657
if isinf(y)
658-
return Complex(copysign(zero(x),x), copysign(pi/2, y))
658+
return Complex(copysign(zero(x),x), copysign(oftype(y, pi/2), y))
659659
end
660-
return Complex(real(1/z), copysign(pi/2, y))
660+
return Complex(real(1/z), copysign(oftype(y, pi/2), y))
661661
elseif ax==1
662662
if y == 0
663663
ξ = copysign(oftype(x,Inf),x)
664664
η = zero(y)
665665
else
666666
ym = ay+ρ
667667
ξ = log(sqrt(sqrt(4+y*y))/sqrt(ym))
668-
η = copysign(pi/2+atan(ym/2), y)/2
668+
η = copysign(oftype(y, pi/2)+atan(ym/2), y)/2
669669
end
670670
else #Normal case
671671
ysq = (ay+ρ)^2

0 commit comments

Comments
 (0)