@@ -1037,24 +1037,22 @@ end
1037
1037
function atanh (z:: Complex{T} ) where T
1038
1038
z = float (z)
1039
1039
Tf = float (T)
1040
- Ω = prevfloat (typemax (Tf))
1041
- θ = sqrt (Ω)/ 4
1042
- ρ = 1 / θ
1043
1040
x, y = reim (z)
1044
1041
ax = abs (x)
1045
1042
ay = abs (y)
1043
+ θ = sqrt (floatmax (Tf))/ 4
1046
1044
if ax > θ || ay > θ # Prevent overflow
1047
1045
if isnan (y)
1048
1046
if isinf (x)
1049
1047
return Complex (copysign (zero (x),x), y)
1050
1048
else
1051
- return Complex (real (1 / z ), y)
1049
+ return Complex (real (inv (z) ), y)
1052
1050
end
1053
1051
end
1054
1052
if isinf (y)
1055
1053
return Complex (copysign (zero (x),x), copysign (oftype (y,pi )/ 2 , y))
1056
1054
end
1057
- return Complex (real (1 / z ), copysign (oftype (y,pi )/ 2 , y))
1055
+ return Complex (real (inv (z) ), copysign (oftype (y,pi )/ 2 , y))
1058
1056
end
1059
1057
β = copysign (one (Tf), x)
1060
1058
z *= β
@@ -1064,16 +1062,15 @@ function atanh(z::Complex{T}) where T
1064
1062
ξ = oftype (x, Inf )
1065
1063
η = y
1066
1064
else
1067
- ym = ay+ ρ
1068
- ξ = log (sqrt (sqrt (4 + y* y))/ sqrt (ym))
1069
- η = copysign (oftype (y,pi )/ 2 + atan (ym/ 2 ), y)/ 2
1065
+ ξ = log (sqrt (sqrt (muladd (y, y, 4 )))/ sqrt (ay))
1066
+ η = copysign (oftype (y,pi )/ 2 + atan (ay/ 2 ), y)/ 2
1070
1067
end
1071
1068
else # Normal case
1072
- ysq = (ay + ρ) ^ 2
1069
+ ysq = ay ^ 2
1073
1070
if x == 0
1074
1071
ξ = x
1075
1072
else
1076
- ξ = log1p (4 x/ ((1 - x) ^ 2 + ysq))/ 4
1073
+ ξ = log1p (4 x/ (muladd (1 - x, 1 - x, ysq) ))/ 4
1077
1074
end
1078
1075
η = angle (Complex ((1 - x)* (1 + x)- ysq, 2 y))/ 2
1079
1076
end
0 commit comments