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

Fix incorrect sign of atanh(complex(x,y)) if x == -1 #31061

Merged
merged 10 commits into from
Feb 19, 2019
12 changes: 8 additions & 4 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,14 @@ function atanh(z::Complex{T}) where T<:AbstractFloat
return Complex(copysign(zero(x),x), copysign(oftype(y,pi)/2, y))
end
return Complex(real(1/z), copysign(oftype(y,pi)/2, y))
elseif ax==1
end
β = copysign(one(T), x)
z *= β
x, y = reim(z)
if x == 1
if y == 0
ξ = copysign(oftype(x,Inf),x)
η = zero(y)
ξ = oftype(x, Inf)
η = y
else
ym = ay+ρ
ξ = log(sqrt(sqrt(4+y*y))/sqrt(ym))
Expand All @@ -970,7 +974,7 @@ function atanh(z::Complex{T}) where T<:AbstractFloat
end
η = angle(Complex((1-x)*(1+x)-ysq, 2y))/2
end
Complex(ξ, η)
β * Complex(ξ, η)
end
atanh(z::Complex) = atanh(float(z))

Expand Down
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,8 @@ this function, see [^AH16_1].
```jldoctest
julia> acos(cos([0.5 0.1; -0.2 0.3]))
2×2 Array{Complex{Float64},2}:
0.5-5.55112e-17im 0.1-2.77556e-17im
-0.2+2.498e-16im 0.3-3.46945e-16im
0.5-8.32667e-17im 0.1+0.0im
-0.2+2.63678e-16im 0.3-3.46945e-16im
```
"""
function acos(A::AbstractMatrix)
Expand Down
9 changes: 9 additions & 0 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,9 @@ end
@test isequal(atanh(complex(-0.0,-Inf)),complex(-0.0,-pi/2))

@test isequal(atanh(complex( 1.0, 0.0)),complex( Inf, 0.0))
@test isequal(atanh(complex( 1.0,-0.0)),complex( Inf,-0.0))
@test isequal(atanh(complex(-1.0, 0.0)),complex(-Inf, 0.0))
@test isequal(atanh(complex(-1.0,-0.0)),complex(-Inf,-0.0))
@test isequal(atanh(complex( 5.0, Inf)),complex( 0.0, pi/2))
@test isequal(atanh(complex( 5.0,-Inf)),complex( 0.0,-pi/2))
@test isequal(atanh(complex( 5.0, NaN)),complex( NaN, NaN))
Expand Down Expand Up @@ -1065,3 +1067,10 @@ end

@test @inferred(2.0^(3.0+0im)) === @inferred((2.0+0im)^(3.0+0im)) === @inferred((2.0+0im)^3.0) === 8.0+0.0im
end

@testset "issue #31054" begin
@test tanh(atanh(complex(1.0,1.0))) == complex(1.0,1.0)
@test tanh(atanh(complex(1.0,-1.0))) == complex(1.0,-1.0)
@test tanh(atanh(complex(-1.0,1.0))) == complex(-1.0,1.0)
@test tanh(atanh(complex(-1.0,-1.0))) == complex(-1.0,-1.0)
end