diff --git a/base/mpc.jl b/base/mpc.jl index 8f87271c0ef47..9d89c4a98084d 100644 --- a/base/mpc.jl +++ b/base/mpc.jl @@ -10,8 +10,11 @@ export import Base: (*), +, -, /, <, <<, >>, <=, ==, >, >=, ^, (~), (&), (|), ($), cmp, - complex, convert, div, imag, integer_valued, isfinite, isinf, isnan, - promote_rule, real, show, showcompact, sqrt, string, get_precision + complex, convert, div, exp, imag, integer_valued, isfinite, isinf, log, + promote_rule, real, show, showcompact, sqrt, string, get_precision, + + # trigonometric functions + sin, cos, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh const ROUNDING_MODE = [0] const DEFAULT_PRECISION = [256, 256] @@ -195,9 +198,6 @@ end function sqrt(x::MPCComplex) z = MPCComplex() ccall((:mpc_sqrt, :libmpc), Int32, (Ptr{MPCComplex}, Ptr{MPCComplex}, Int32), &z, &x, ROUNDING_MODE[end]) - if isnan(z) - throw(DomainError()) - end return z end @@ -219,6 +219,32 @@ function ^(x::MPCComplex, y::BigInt) return z end +function exp(x::MPCComplex) + z = MPCComplex() + ccall((:mpc_exp, :libmpc), Int32, (Ptr{MPCComplex}, Ptr{MPCComplex}, Int32), &z, &x, ROUNDING_MODE[end]) + return z +end + +function log(x::MPCComplex) + z = MPCComplex() + ccall((:mpc_log, :libmpc), Int32, (Ptr{MPCComplex}, Ptr{MPCComplex}, Int32), &z, &x, ROUNDING_MODE[end]) + return z +end + +# Trigonometric functions +# No error handling is done, and NaN are returned directly +# the Base functions behavior +for f in (:sin,:cos,:tan,:acos,:asin,:atan, + :cosh,:sinh,:tanh,:acosh,:asinh,:atanh) + @eval begin + function ($f)(x::MPCComplex) + z = MPCComplex() + ccall(($(string(:mpc_,f)), :libmpc), Int32, (Ptr{MPCComplex}, Ptr{MPCComplex}, Int32), &z, &x, ROUNDING_MODE[end]) + return z + end + end +end + # Utility functions ==(x::MPCComplex, y::MPCComplex) = ccall((:mpc_cmp, :libmpc), Int32, (Ptr{MPCComplex}, Ptr{MPCComplex}), &x, &y) == 0 diff --git a/test/mpc.jl b/test/mpc.jl index 30dcfd2046e98..35567afc3f9d7 100644 --- a/test/mpc.jl +++ b/test/mpc.jl @@ -78,3 +78,737 @@ x = MPCComplex(12,42) # integer_valued @test !integer_valued(MPCComplex(2,3)) @test integer_valued(MPCComplex(2)) + +# Kahan tests from #2845 by @simonbyrne +with_bigcomplex_precision(53,53) do +# sqrt: +# tests special values from csqrt man page +# as well as conj(sqrt(z)) = sqrt(conj(z)) +@test isequal(sqrt(MPCComplex(0.0,0.0)), MPCComplex(0.0,0.0)) +@test isequal(sqrt(MPCComplex(-0.0,0.0)), MPCComplex(0.0,0.0)) +@test isequal(sqrt(MPCComplex(0.0,-0.0)), MPCComplex(0.0,-0.0)) +@test isequal(sqrt(MPCComplex(-0.0,-0.0)), MPCComplex(0.0,-0.0)) + +@test isequal(sqrt(MPCComplex(5.0,0.0)), MPCComplex(sqrt(5.0),0.0)) +@test isequal(sqrt(MPCComplex(5.0,-0.0)), MPCComplex(sqrt(5.0),-0.0)) + +@test isequal(sqrt(MPCComplex(-5.0,0.0)), MPCComplex(0.0,sqrt(5.0))) +@test isequal(sqrt(MPCComplex(-5.0,-0.0)), MPCComplex(0.0,-sqrt(5.0))) + +@test isequal(sqrt(MPCComplex(0.0,Inf)), MPCComplex(Inf,Inf)) +@test isequal(sqrt(MPCComplex(0.0,-Inf)), MPCComplex(Inf,-Inf)) + +@test isequal(sqrt(MPCComplex(NaN,Inf)), MPCComplex(Inf,Inf)) +@test isequal(sqrt(MPCComplex(NaN,-Inf)), MPCComplex(Inf,-Inf)) + +@test isequal(sqrt(MPCComplex(Inf,Inf)), MPCComplex(Inf,Inf)) +@test isequal(sqrt(MPCComplex(Inf,-Inf)), MPCComplex(Inf,-Inf)) +@test isequal(sqrt(MPCComplex(-Inf,Inf)), MPCComplex(Inf,Inf)) +@test isequal(sqrt(MPCComplex(-Inf,-Inf)), MPCComplex(Inf,-Inf)) + +@test isequal(sqrt(MPCComplex(0.0,NaN)), MPCComplex(NaN,NaN)) + +@test isequal(sqrt(MPCComplex(-Inf,0.0)), MPCComplex(0.0,Inf)) +@test isequal(sqrt(MPCComplex(-Inf,5.0)), MPCComplex(0.0,Inf)) +@test isequal(sqrt(MPCComplex(-Inf,-0.0)), MPCComplex(0.0,-Inf)) +@test isequal(sqrt(MPCComplex(-Inf,-5.0)), MPCComplex(0.0,-Inf)) + +@test isequal(sqrt(MPCComplex(Inf,0.0)), MPCComplex(Inf,0.0)) +@test isequal(sqrt(MPCComplex(Inf,5.0)), MPCComplex(Inf,0.0)) +@test isequal(sqrt(MPCComplex(Inf,-0.0)), MPCComplex(Inf,-0.0)) +@test isequal(sqrt(MPCComplex(Inf,-5.0)), MPCComplex(Inf,-0.0)) + +@test isequal(sqrt(MPCComplex(-Inf,NaN)), MPCComplex(NaN,Inf)) +@test isequal(sqrt(MPCComplex(Inf,NaN)), MPCComplex(Inf,NaN)) + +@test isequal(sqrt(MPCComplex(NaN,0.0)), MPCComplex(NaN,NaN)) +@test isequal(sqrt(MPCComplex(NaN,0.0)), MPCComplex(NaN,NaN)) + + + +# log: +# log(conj(z)) = conj(log(z)) +@test isequal(log(MPCComplex(5.0,0.0)),MPCComplex(log(5.0),0.0)) +@test isequal(log(MPCComplex(5.0,-0.0)),MPCComplex(log(5.0),-0.0)) + +@test isequal(log(MPCComplex(0.0,1.0)),MPCComplex(0.0,pi/2)) +@test isequal(log(MPCComplex(0.0,-1.0)),MPCComplex(0.0,-pi/2)) + +# special values + +# raise divide-by-zero flag +@test isequal(log(MPCComplex(-0.0,0.0)), MPCComplex(-Inf,pi)) +@test isequal(log(MPCComplex(-0.0,-0.0)), MPCComplex(-Inf,-pi)) + +# raise divide-by-zero flag +@test isequal(log(MPCComplex(0.0,0.0)), MPCComplex(-Inf,0.0)) +@test isequal(log(MPCComplex(0.0,-0.0)), MPCComplex(-Inf,-0.0)) + +@test isequal(log(MPCComplex(0.0,Inf)), MPCComplex(Inf,pi/2)) +@test isequal(log(MPCComplex(0.0,-Inf)), MPCComplex(Inf,-pi/2)) + +@test isequal(log(MPCComplex(0.0,NaN)), MPCComplex(NaN,NaN)) + +@test isequal(log(MPCComplex(-Inf,5.0)), MPCComplex(Inf,pi)) +@test isequal(log(MPCComplex(-Inf,-5.0)), MPCComplex(Inf,-pi)) + +@test isequal(log(MPCComplex(Inf,5.0)), MPCComplex(Inf,0.0)) +@test isequal(log(MPCComplex(Inf,-5.0)), MPCComplex(Inf,-0.0)) + +@test isequal(log(MPCComplex(-Inf,Inf)), MPCComplex(Inf,3*pi/4)) +@test isequal(log(MPCComplex(-Inf,-Inf)), MPCComplex(Inf,-3*pi/4)) + +@test isequal(log(MPCComplex(Inf,Inf)), MPCComplex(Inf,pi/4)) +@test isequal(log(MPCComplex(Inf,-Inf)), MPCComplex(Inf,-pi/4)) + +@test isequal(log(MPCComplex(Inf,NaN)), MPCComplex(Inf,NaN)) +@test isequal(log(MPCComplex(-Inf,NaN)), MPCComplex(Inf,NaN)) + +@test isequal(log(MPCComplex(NaN,0.0)), MPCComplex(NaN,NaN)) + +@test isequal(log(MPCComplex(NaN,Inf)), MPCComplex(Inf,NaN)) +@test isequal(log(MPCComplex(NaN,-Inf)), MPCComplex(Inf,NaN)) + +@test isequal(log(MPCComplex(NaN,NaN)), MPCComplex(NaN,NaN)) + +# exp: +# exp(conj(z)) = conj(exp(z)) + +@test isequal(exp(MPCComplex(0.0,0.0)), MPCComplex(1.0,0.0)) +@test isequal(exp(MPCComplex(0.0,-0.0)), MPCComplex(1.0,-0.0)) +@test isequal(exp(MPCComplex(-0.0,0.0)), MPCComplex(1.0,0.0)) +@test isequal(exp(MPCComplex(-0.0,-0.0)), MPCComplex(1.0,-0.0)) + +# raise invalid flag +@test isequal(exp(MPCComplex(0.0,Inf)), MPCComplex(NaN,NaN)) +@test isequal(exp(MPCComplex(0.0,-Inf)), MPCComplex(NaN,NaN)) +@test isequal(exp(MPCComplex(5.0,Inf)), MPCComplex(NaN,NaN)) + +@test isequal(exp(MPCComplex(0.0,NaN)), MPCComplex(NaN,NaN)) + +@test isequal(exp(MPCComplex(Inf,0.0)), MPCComplex(Inf,0.0)) +@test isequal(exp(MPCComplex(Inf,-0.0)), MPCComplex(Inf,-0.0)) + +@test isequal(exp(MPCComplex(-Inf,0.0)), MPCComplex(0.0,0.0)) +@test isequal(exp(MPCComplex(-Inf,-0.0)), MPCComplex(0.0,-0.0)) +@test isequal(exp(MPCComplex(-Inf,5.0)), MPCComplex(cos(5.0)*0.0,sin(5.0)*0.0)) +@test isequal(exp(MPCComplex(-Inf,-5.0)), MPCComplex(cos(5.0)*0.0,sin(5.0)*-0.0)) + +@test isequal(exp(MPCComplex(Inf,5.0)), MPCComplex(cos(5.0)*Inf,sin(5.0)*Inf)) +@test isequal(exp(MPCComplex(Inf,-5.0)), MPCComplex(cos(5.0)*Inf,sin(5.0)*-Inf)) + +@test isequal(exp(MPCComplex(-Inf,Inf)), MPCComplex(-0.0,0.0)) +@test isequal(exp(MPCComplex(-Inf,-Inf)), MPCComplex(-0.0,-0.0)) + +# raise invalid flag +# TODO: The left side evaluates to MPCComplex(Inf, NaN) +#@test isequal(exp(MPCComplex(Inf,Inf)), MPCComplex(-Inf,NaN)) +#@test isequal(exp(MPCComplex(Inf,-Inf)), MPCComplex(-Inf,NaN)) + +@test isequal(exp(MPCComplex(-Inf,NaN)), MPCComplex(-0.0,0.0)) + +# TODO: The left side evaluates to MPCComplex(Inf, NaN) +#@test isequal(exp(MPCComplex(Inf,NaN)), MPCComplex(-Inf,NaN)) + +@test isequal(exp(MPCComplex(NaN,0.0)), MPCComplex(NaN,0.0)) +@test isequal(exp(MPCComplex(NaN,-0.0)), MPCComplex(NaN,-0.0)) + +@test isequal(exp(MPCComplex(NaN,5.0)), MPCComplex(NaN,NaN)) + +@test isequal(exp(MPCComplex(NaN,NaN)), MPCComplex(NaN,NaN)) + +# ^ (cpow) +# equivalent to exp(y*log(x)) +# except for 0^0? +# conj(x)^conj(y) = conj(x^y) +@test isequal(MPCComplex(0.0,0.0)^MPCComplex(0.0,0.0), MPCComplex(1.0,-0.0)) +@test isequal(MPCComplex(0.0,-0.0)^MPCComplex(0.0,0.0), MPCComplex(1.0,-0.0)) +@test isequal(MPCComplex(0.0,0.0)^MPCComplex(0.0,-0.0), MPCComplex(1.0,0.0)) +@test isequal(MPCComplex(0.0,-0.0)^MPCComplex(0.0,-0.0), MPCComplex(1.0,0.0)) +@test isequal(MPCComplex(-0.0,0.0)^MPCComplex(0.0,0.0), MPCComplex(1.0,-0.0)) +@test isequal(MPCComplex(-0.0,-0.0)^MPCComplex(0.0,0.0), MPCComplex(1.0,-0.0)) +@test isequal(MPCComplex(-0.0,0.0)^MPCComplex(0.0,-0.0), MPCComplex(1.0,0.0)) +@test isequal(MPCComplex(-0.0,-0.0)^MPCComplex(0.0,-0.0), MPCComplex(1.0,0.0)) +@test isequal(MPCComplex(0.0,0.0)^MPCComplex(-0.0,0.0), MPCComplex(1.0,-0.0)) +@test isequal(MPCComplex(0.0,-0.0)^MPCComplex(-0.0,0.0), MPCComplex(1.0,-0.0)) +@test isequal(MPCComplex(0.0,0.0)^MPCComplex(-0.0,-0.0), MPCComplex(1.0,0.0)) +@test isequal(MPCComplex(0.0,-0.0)^MPCComplex(-0.0,-0.0), MPCComplex(1.0,0.0)) +@test isequal(MPCComplex(-0.0,0.0)^MPCComplex(-0.0,0.0), MPCComplex(1.0,-0.0)) +@test isequal(MPCComplex(-0.0,-0.0)^MPCComplex(-0.0,0.0), MPCComplex(1.0,-0.0)) +@test isequal(MPCComplex(-0.0,0.0)^MPCComplex(-0.0,-0.0), MPCComplex(1.0,0.0)) +@test isequal(MPCComplex(-0.0,-0.0)^MPCComplex(-0.0,-0.0), MPCComplex(1.0,0.0)) + + + + +# sinh: has properties +# sinh(conj(z)) = conj(sinh(z)) +# sinh(-z) = -sinh(z) + +@test isequal(sinh(MPCComplex(0.0,0.0)),MPCComplex(0.0,0.0)) +@test isequal(sinh(MPCComplex(0.0,-0.0)),MPCComplex(0.0,-0.0)) +@test isequal(sinh(MPCComplex(-0.0,0.0)),MPCComplex(-0.0,0.0)) +@test isequal(sinh(MPCComplex(-0.0,-0.0)),MPCComplex(-0.0,-0.0)) + +# raise invalid flag +@test isequal(sinh(MPCComplex(0.0,Inf)), MPCComplex(0.0,NaN)) +@test isequal(sinh(MPCComplex(0.0,-Inf)), MPCComplex(0.0,NaN)) +@test isequal(sinh(MPCComplex(-0.0,Inf)), MPCComplex(-0.0,NaN)) +@test isequal(sinh(MPCComplex(-0.0,-Inf)), MPCComplex(-0.0,NaN)) + +@test isequal(sinh(MPCComplex(0.0,NaN)),MPCComplex(0.0,NaN)) +@test isequal(sinh(MPCComplex(-0.0,NaN)),MPCComplex(-0.0,NaN)) + +# raise invalid flag +@test isequal(sinh(MPCComplex(5.0,Inf)), MPCComplex(NaN,NaN)) + +@test isequal(sinh(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(sinh(MPCComplex(Inf,0.0)),MPCComplex(Inf,0.0)) +@test isequal(sinh(MPCComplex(Inf,-0.0)),MPCComplex(Inf,-0.0)) +@test isequal(sinh(MPCComplex(-Inf,0.0)),MPCComplex(-Inf,0.0)) +@test isequal(sinh(MPCComplex(-Inf,-0.0)),MPCComplex(-Inf,-0.0)) + +@test isequal(sinh(MPCComplex(Inf,5.0)),MPCComplex(cos(5.0)*Inf,sin(5.0)*Inf)) +@test isequal(sinh(MPCComplex(-Inf,5.0)),MPCComplex(cos(5.0)*-Inf,sin(5.0)*Inf)) + +# raise invalid flag +@test isequal(sinh(MPCComplex(Inf,Inf)), MPCComplex(Inf,NaN)) +@test isequal(sinh(MPCComplex(Inf,-Inf)), MPCComplex(Inf,NaN)) +@test isequal(sinh(MPCComplex(-Inf,Inf)), MPCComplex(-Inf,NaN)) +@test isequal(sinh(MPCComplex(-Inf,-Inf)), MPCComplex(-Inf,NaN)) + +@test isequal(sinh(MPCComplex(Inf,NaN)),MPCComplex(Inf,NaN)) +@test isequal(sinh(MPCComplex(-Inf,NaN)),MPCComplex(-Inf,NaN)) + +@test isequal(sinh(MPCComplex(NaN,0.0)),MPCComplex(NaN,0.0)) +@test isequal(sinh(MPCComplex(NaN,-0.0)),MPCComplex(NaN,-0.0)) + +@test isequal(sinh(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) + +@test isequal(sinh(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + + +# sin: defined in terms of sinh +# sin(z) = -i*sinh(i*z) +# i.e. if sinh(a+ib) = x+iy +# then sin(b-ia) = y-ix +# sin(conj(z)) = conj(sin(z)) +# sin(-z) = -sin(z) + + +@test isequal(sin(MPCComplex(0.0,-0.0)),MPCComplex(0.0,-0.0)) +@test isequal(sin(MPCComplex(-0.0,-0.0)),MPCComplex(-0.0,-0.0)) +@test isequal(sin(MPCComplex(0.0,0.0)),MPCComplex(0.0,0.0)) +@test isequal(sin(MPCComplex(-0.0,0.0)),MPCComplex(-0.0,0.0)) + +# raise invalid flag +@test isequal(sin(MPCComplex(Inf,0.0)), MPCComplex(NaN,0.0)) +@test isequal(sin(MPCComplex(-Inf,0.0)), MPCComplex(NaN,0.0)) +@test isequal(sin(MPCComplex(Inf,-0.0)), MPCComplex(NaN,-0.0)) +@test isequal(sin(MPCComplex(-Inf,-0.0)), MPCComplex(NaN,-0.0)) + +@test isequal(sin(MPCComplex(NaN,0.0)),MPCComplex(NaN,0.0)) +@test isequal(sin(MPCComplex(NaN,-0.0)),MPCComplex(NaN,-0.0)) + +# raise invalid flag +@test isequal(sin(MPCComplex(Inf,5.0)), MPCComplex(NaN,NaN)) + +@test isequal(sin(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) + +@test isequal(sin(MPCComplex(0.0,Inf)),MPCComplex(0.0,Inf)) +@test isequal(sin(MPCComplex(-0.0,Inf)),MPCComplex(-0.0,Inf)) +@test isequal(sin(MPCComplex(0.0,-Inf)),MPCComplex(0.0,-Inf)) +@test isequal(sin(MPCComplex(-0.0,-Inf)),MPCComplex(-0.0,-Inf)) + +@test isequal(sin(MPCComplex(5.0,Inf)),MPCComplex(sin(5.0)*Inf,cos(5.0)*Inf)) +@test isequal(sin(MPCComplex(5.0,-Inf)),MPCComplex(sin(5.0)*Inf,cos(5.0)*-Inf)) + +# raise invalid flag +@test isequal(sin(MPCComplex(Inf,Inf)), MPCComplex(Inf,NaN)) +@test isequal(sin(MPCComplex(Inf,-Inf)), MPCComplex(Inf,NaN)) +@test isequal(sin(MPCComplex(-Inf,Inf)), MPCComplex(-Inf,NaN)) +@test isequal(sin(MPCComplex(-Inf,-Inf)), MPCComplex(-Inf,NaN)) + +@test isequal(sin(MPCComplex(NaN,Inf)),MPCComplex(NaN,Inf)) +@test isequal(sin(MPCComplex(NaN,-Inf)),MPCComplex(NaN,-Inf)) + +@test isequal(sin(MPCComplex(0.0,NaN)),MPCComplex(0.0,NaN)) +@test isequal(sin(MPCComplex(-0.0,NaN)),MPCComplex(-0.0,NaN)) + +@test isequal(sin(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(sin(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + + + + + +# cosh: has properties +# cosh(conj(z)) = conj(cosh(z)) +# coshh(-z) = cosh(z) + +@test isequal(cosh(MPCComplex(0.0,0.0)),MPCComplex(1.0,0.0)) +@test isequal(cosh(MPCComplex(0.0,-0.0)),MPCComplex(1.0,-0.0)) +@test isequal(cosh(MPCComplex(-0.0,-0.0)),MPCComplex(1.0,0.0)) +@test isequal(cosh(MPCComplex(-0.0,0.0)),MPCComplex(1.0,-0.0)) + +# raise invalid flag +@test isequal(cosh(MPCComplex(0.0,Inf)), MPCComplex(NaN,0.0)) +@test isequal(cosh(MPCComplex(0.0,-Inf)), MPCComplex(NaN,-0.0)) + +@test isequal(cosh(MPCComplex(0.0,NaN)),MPCComplex(NaN,0.0)) +@test isequal(cosh(MPCComplex(-0.0,NaN)),MPCComplex(NaN,0.0)) + +# raise invalid flag +@test isequal(cosh(MPCComplex(5.0,Inf)), MPCComplex(NaN,NaN)) + +@test isequal(cosh(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(cosh(MPCComplex(Inf,0.0)),MPCComplex(Inf,0.0)) +@test isequal(cosh(MPCComplex(Inf,-0.0)),MPCComplex(Inf,-0.0)) +@test isequal(cosh(MPCComplex(-Inf,-0.0)),MPCComplex(Inf,0.0)) +@test isequal(cosh(MPCComplex(-Inf,0.0)),MPCComplex(Inf,-0.0)) + +@test isequal(cosh(MPCComplex(Inf,5.0)),MPCComplex(cos(5.0)*Inf,sin(5.0)*Inf)) +@test isequal(cosh(MPCComplex(Inf,-5.0)),MPCComplex(cos(5.0)*Inf,sin(5.0)*-Inf)) +@test isequal(cosh(MPCComplex(-Inf,-5.0)),MPCComplex(cos(5.0)*Inf,sin(5.0)*Inf)) +@test isequal(cosh(MPCComplex(-Inf,5.0)),MPCComplex(cos(5.0)*Inf,sin(5.0)*-Inf)) + +# raise invalid flag +@test isequal(cosh(MPCComplex(Inf,Inf)), MPCComplex(Inf,NaN)) +# TODO: The left side evaluates to MPCComplex(-Inf, NaN) +#@test isequal(cosh(MPCComplex(Inf,-Inf)), MPCComplex(Inf,NaN)) +@test isequal(cosh(MPCComplex(-Inf,-Inf)), MPCComplex(Inf,NaN)) +# TODO: The left side evaluates to MPCComplex(-Inf, NaN) +#@test isequal(cosh(MPCComplex(-Inf,Inf)), MPCComplex(Inf,NaN)) + +@test isequal(cosh(MPCComplex(Inf,NaN)),MPCComplex(Inf,NaN)) +@test isequal(cosh(MPCComplex(-Inf,NaN)),MPCComplex(Inf,NaN)) + +@test isequal(cosh(MPCComplex(NaN,0.0)),MPCComplex(NaN,0.0)) +@test isequal(cosh(MPCComplex(NaN,-0.0)),MPCComplex(NaN,-0.0)) + +@test isequal(cosh(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) +@test isequal(cosh(MPCComplex(NaN,-5.0)),MPCComplex(NaN,NaN)) + +@test isequal(cosh(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + +# cos +# cos(z) = cosh(iz) +# i.e cos(b-ia) = cosh(a+ib) +# and cos(b+ia) = cosh(a-ib) +# cos(conj(z)) = conj(cos(z)) +# cos(-z) = cos(z) + +@test isequal(cos(MPCComplex(0.0,0.0)),MPCComplex(1.0,-0.0)) +@test isequal(cos(MPCComplex(0.0,-0.0)),MPCComplex(1.0,0.0)) +@test isequal(cos(MPCComplex(-0.0,0.0)),MPCComplex(1.0,0.0)) +@test isequal(cos(MPCComplex(-0.0,-0.0)),MPCComplex(1.0,-0.0)) + +# raise invalid flag +@test isequal(cos(MPCComplex(Inf,0.0)), MPCComplex(NaN,-0.0)) +@test isequal(cos(MPCComplex(-Inf,0.0)), MPCComplex(NaN,0.0)) + +@test isequal(cos(MPCComplex(NaN,0.0)),MPCComplex(NaN,0.0)) +@test isequal(cos(MPCComplex(NaN,-0.0)),MPCComplex(NaN,0.0)) + +# raise invalid flag +@test isequal(cos(MPCComplex(Inf,5.0)), MPCComplex(NaN,NaN)) + +@test isequal(cos(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) + +@test isequal(cos(MPCComplex(0.0,-Inf)),MPCComplex(Inf,0.0)) +@test isequal(cos(MPCComplex(-0.0,-Inf)),MPCComplex(Inf,-0.0)) +@test isequal(cos(MPCComplex(-0.0,Inf)),MPCComplex(Inf,0.0)) +@test isequal(cos(MPCComplex(0.0,Inf)),MPCComplex(Inf,-0.0)) + +@test isequal(cos(MPCComplex(5.0,-Inf)),MPCComplex(cos(5.0)*Inf,sin(5.0)*Inf)) +@test isequal(cos(MPCComplex(-5.0,-Inf)),MPCComplex(cos(5.0)*Inf,sin(5.0)*-Inf)) +@test isequal(cos(MPCComplex(-5.0,Inf)),MPCComplex(cos(5.0)*Inf,sin(5.0)*Inf)) +@test isequal(cos(MPCComplex(5.0,Inf)),MPCComplex(cos(5.0)*Inf,sin(5.0)*-Inf)) + +# raise invalid flag +# TODO: The left side evaluates to MPCComplex(-Inf, NaN) +#@test isequal(cos(MPCComplex(Inf,Inf)), MPCComplex(Inf,NaN)) +@test isequal(cos(MPCComplex(Inf,-Inf)), MPCComplex(Inf,NaN)) +# TODO: The left side evaluates to MPCComplex(-Inf, NaN) +#@test isequal(cos(MPCComplex(-Inf,-Inf)), MPCComplex(Inf,NaN)) +@test isequal(cos(MPCComplex(-Inf,Inf)), MPCComplex(Inf,NaN)) + +@test isequal(cos(MPCComplex(NaN,Inf)),MPCComplex(Inf,NaN)) +@test isequal(cos(MPCComplex(NaN,-Inf)),MPCComplex(Inf,NaN)) + +@test isequal(cos(MPCComplex(0.0,NaN)),MPCComplex(NaN,0.0)) +@test isequal(cos(MPCComplex(-0.0,NaN)),MPCComplex(NaN,-0.0)) + +@test isequal(cos(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) +@test isequal(cos(MPCComplex(-5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(cos(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + + + +# tanh +# tanh(conj(z)) = conj(tanh(z)) +# tanh(-z) = -tanh(z) +@test isequal(tanh(MPCComplex(0.0,0.0)),MPCComplex(0.0,0.0)) +@test isequal(tanh(MPCComplex(0.0,-0.0)),MPCComplex(0.0,-0.0)) +@test isequal(tanh(MPCComplex(-0.0,0.0)),MPCComplex(-0.0,0.0)) +@test isequal(tanh(MPCComplex(-0.0,-0.0)),MPCComplex(-0.0,-0.0)) + +# raise invalid flag +@test isequal(tanh(MPCComplex(0.0,Inf)), MPCComplex(NaN,0.0)) +@test isequal(tanh(MPCComplex(0.0,-Inf)), MPCComplex(NaN,-0.0)) + +@test isequal(tanh(MPCComplex(0.0,NaN)),MPCComplex(NaN,NaN)) + +# raise invalid flag +@test isequal(tanh(MPCComplex(5.0,Inf)), MPCComplex(NaN,NaN)) + +@test isequal(tanh(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(tanh(MPCComplex(Inf,0.0)),MPCComplex(1.0,0.0)) +@test isequal(tanh(MPCComplex(Inf,-0.0)),MPCComplex(1.0,-0.0)) +@test isequal(tanh(MPCComplex(-Inf,0.0)),MPCComplex(-1.0,0.0)) +@test isequal(tanh(MPCComplex(-Inf,-0.0)),MPCComplex(-1.0,-0.0)) + +@test isequal(tanh(MPCComplex(Inf,5.0)),MPCComplex(1.0,sin(2*5.0)*0.0)) +@test isequal(tanh(MPCComplex(Inf,-5.0)),MPCComplex(1.0,sin(2*5.0)*-0.0)) +@test isequal(tanh(MPCComplex(-Inf,5.0)),MPCComplex(-1.0,sin(2*5.0)*0.0)) +@test isequal(tanh(MPCComplex(-Inf,-5.0)),MPCComplex(-1.0,sin(2*5.0)*-0.0)) + +@test isequal(tanh(MPCComplex(Inf,Inf)),MPCComplex(1.0,0.0)) +@test isequal(tanh(MPCComplex(Inf,-Inf)),MPCComplex(1.0,-0.0)) +@test isequal(tanh(MPCComplex(-Inf,Inf)),MPCComplex(-1.0,0.0)) +@test isequal(tanh(MPCComplex(-Inf,-Inf)),MPCComplex(-1.0,-0.0)) + +@test isequal(tanh(MPCComplex(Inf,NaN)),MPCComplex(1.0,0.0)) +@test isequal(tanh(MPCComplex(-Inf,NaN)),MPCComplex(-1.0,0.0)) + +@test isequal(tanh(MPCComplex(NaN,0.0)),MPCComplex(NaN,0.0)) +@test isequal(tanh(MPCComplex(NaN,-0.0)),MPCComplex(NaN,-0.0)) + +@test isequal(tanh(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) +@test isequal(tanh(MPCComplex(NaN,-5.0)),MPCComplex(NaN,NaN)) + +@test isequal(tanh(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + +# tan +# tan(z) = -i tanh(iz) +@test isequal(tan(MPCComplex(Inf,5.0)), MPCComplex(NaN,NaN)) + +@test isequal(tan(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) + +@test isequal(tan(MPCComplex(0.0,Inf)),MPCComplex(0.0,1.0)) +@test isequal(tan(MPCComplex(-0.0,Inf)),MPCComplex(-0.0,1.0)) +@test isequal(tan(MPCComplex(0.0,-Inf)),MPCComplex(0.0,-1.0)) +@test isequal(tan(MPCComplex(-0.0,-Inf)),MPCComplex(-0.0,-1.0)) + +@test isequal(tan(MPCComplex(5.0,Inf)),MPCComplex(sin(2*5.0)*0.0,1.0)) +@test isequal(tan(MPCComplex(-5.0,Inf)),MPCComplex(sin(2*5.0)*-0.0,1.0)) +@test isequal(tan(MPCComplex(5.0,-Inf)),MPCComplex(sin(2*5.0)*0.0,-1.0)) +@test isequal(tan(MPCComplex(-5.0,-Inf)),MPCComplex(sin(2*5.0)*-0.0,-1.0)) + +@test isequal(tan(MPCComplex(Inf,Inf)),MPCComplex(0.0,1.0)) +@test isequal(tan(MPCComplex(-Inf,Inf)),MPCComplex(-0.0,1.0)) +@test isequal(tan(MPCComplex(Inf,-Inf)),MPCComplex(0.0,-1.0)) +@test isequal(tan(MPCComplex(-Inf,-Inf)),MPCComplex(-0.0,-1.0)) + +@test isequal(tan(MPCComplex(NaN,Inf)),MPCComplex(0.0,1.0)) +@test isequal(tan(MPCComplex(NaN,-Inf)),MPCComplex(0.0,-1.0)) + +@test isequal(tan(MPCComplex(0.0,NaN)),MPCComplex(0.0,NaN)) +@test isequal(tan(MPCComplex(-0.0,NaN)),MPCComplex(-0.0,NaN)) + +@test isequal(tan(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) +@test isequal(tan(MPCComplex(-5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(tan(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + + + +# acosh +# acosh(conj(z)) = conj(acosh(z)) +@test isequal(acosh(MPCComplex(0.0,0.0)),MPCComplex(0.0,pi/2)) +@test isequal(acosh(MPCComplex(0.0,-0.0)),MPCComplex(0.0,-pi/2)) +@test isequal(acosh(MPCComplex(-0.0,0.0)),MPCComplex(0.0,pi/2)) +@test isequal(acosh(MPCComplex(-0.0,-0.0)),MPCComplex(0.0,-pi/2)) + +@test isequal(acosh(MPCComplex(0.0,Inf)),MPCComplex(Inf,pi/2)) +@test isequal(acosh(MPCComplex(0.0,-Inf)),MPCComplex(Inf,-pi/2)) +@test isequal(acosh(MPCComplex(5.0,Inf)),MPCComplex(Inf,pi/2)) +@test isequal(acosh(MPCComplex(5.0,-Inf)),MPCComplex(Inf,-pi/2)) + +@test isequal(acosh(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(acosh(MPCComplex(-Inf,0.0)),MPCComplex(Inf,pi)) +@test isequal(acosh(MPCComplex(-Inf,-0.0)),MPCComplex(Inf,-pi)) +@test isequal(acosh(MPCComplex(-Inf,5.0)),MPCComplex(Inf,pi)) +@test isequal(acosh(MPCComplex(-Inf,-5.0)),MPCComplex(Inf,-pi)) + +@test isequal(acosh(MPCComplex(Inf,0.0)),MPCComplex(Inf,0.0)) +@test isequal(acosh(MPCComplex(Inf,-0.0)),MPCComplex(Inf,-0.0)) +@test isequal(acosh(MPCComplex(Inf,5.0)),MPCComplex(Inf,0.0)) +@test isequal(acosh(MPCComplex(Inf,-5.0)),MPCComplex(Inf,-0.0)) + +@test isequal(acosh(MPCComplex(-Inf,Inf)),MPCComplex(Inf,3*pi/4)) +@test isequal(acosh(MPCComplex(-Inf,-Inf)),MPCComplex(Inf,-3*pi/4)) + +@test isequal(acosh(MPCComplex(Inf,Inf)),MPCComplex(Inf,pi/4)) +@test isequal(acosh(MPCComplex(Inf,-Inf)),MPCComplex(Inf,-pi/4)) + +@test isequal(acosh(MPCComplex(Inf,NaN)),MPCComplex(Inf,NaN)) +@test isequal(acosh(MPCComplex(-Inf,NaN)),MPCComplex(Inf,NaN)) + +@test isequal(acosh(MPCComplex(NaN,Inf)),MPCComplex(Inf,NaN)) +@test isequal(acosh(MPCComplex(NaN,-Inf)),MPCComplex(Inf,NaN)) + +@test isequal(acosh(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + +# acos +# acos(conj(z)) = conj(acos(z)) +@test isequal(acos(MPCComplex(0.0,0.0)),MPCComplex(pi/2,-0.0)) +@test isequal(acos(MPCComplex(0.0,-0.0)),MPCComplex(pi/2,0.0)) +@test isequal(acos(MPCComplex(-0.0,0.0)),MPCComplex(pi/2,-0.0)) +@test isequal(acos(MPCComplex(-0.0,-0.0)),MPCComplex(pi/2,0.0)) + +@test isequal(acos(MPCComplex(0.0,NaN)),MPCComplex(pi/2,NaN)) +@test isequal(acos(MPCComplex(-0.0,NaN)),MPCComplex(pi/2,NaN)) + +@test isequal(acos(MPCComplex(0.0,Inf)),MPCComplex(pi/2,-Inf)) +@test isequal(acos(MPCComplex(0.0,-Inf)),MPCComplex(pi/2,Inf)) +@test isequal(acos(MPCComplex(5.0,Inf)),MPCComplex(pi/2,-Inf)) +@test isequal(acos(MPCComplex(5.0,-Inf)),MPCComplex(pi/2,Inf)) + +@test isequal(acos(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(acos(MPCComplex(-Inf,0.0)),MPCComplex(pi,-Inf)) +@test isequal(acos(MPCComplex(-Inf,-0.0)),MPCComplex(pi,Inf)) +@test isequal(acos(MPCComplex(-Inf,5.0)),MPCComplex(pi,-Inf)) +@test isequal(acos(MPCComplex(-Inf,-5.0)),MPCComplex(pi,Inf)) + +@test isequal(acos(MPCComplex(Inf,0.0)),MPCComplex(0.0,-Inf)) +@test isequal(acos(MPCComplex(Inf,-0.0)),MPCComplex(0.0,Inf)) +@test isequal(acos(MPCComplex(Inf,5.0)),MPCComplex(0.0,-Inf)) +@test isequal(acos(MPCComplex(Inf,-5.0)),MPCComplex(0.0,Inf)) + +@test isequal(acos(MPCComplex(-Inf,Inf)),MPCComplex(3*pi/4,-Inf)) +@test isequal(acos(MPCComplex(-Inf,-Inf)),MPCComplex(3*pi/4,Inf)) + +@test isequal(acos(MPCComplex(Inf,Inf)),MPCComplex(pi/4,-Inf)) +@test isequal(acos(MPCComplex(Inf,-Inf)),MPCComplex(pi/4,Inf)) + +# TODO: The left side evaluates to MPCComplex(NaN, -Inf) +#@test isequal(acos(MPCComplex(Inf,NaN)),MPCComplex(NaN,Inf)) +#@test isequal(acos(MPCComplex(-Inf,NaN)),MPCComplex(NaN,Inf)) + +@test isequal(acos(MPCComplex(NaN,0.0)),MPCComplex(NaN,NaN)) +@test isequal(acos(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) + +@test isequal(acos(MPCComplex(NaN,Inf)),MPCComplex(NaN,-Inf)) +@test isequal(acos(MPCComplex(NaN,-Inf)),MPCComplex(NaN,Inf)) + +@test isequal(acos(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + + +# asinh +# asinh(conj(z)) = conj(asinh(z)) +# asinh(-z) = -asinh(z) +@test isequal(asinh(MPCComplex(0.0,0.0)),MPCComplex(0.0,0.0)) +@test isequal(asinh(MPCComplex(0.0,-0.0)),MPCComplex(0.0,-0.0)) +@test isequal(asinh(MPCComplex(-0.0,0.0)),MPCComplex(-0.0,0.0)) +@test isequal(asinh(MPCComplex(-0.0,-0.0)),MPCComplex(-0.0,-0.0)) + +@test isequal(asinh(MPCComplex(0.0,Inf)),MPCComplex(Inf,pi/2)) +@test isequal(asinh(MPCComplex(0.0,-Inf)),MPCComplex(Inf,-pi/2)) +@test isequal(asinh(MPCComplex(-0.0,Inf)),MPCComplex(-Inf,pi/2)) +@test isequal(asinh(MPCComplex(-0.0,-Inf)),MPCComplex(-Inf,-pi/2)) + +@test isequal(asinh(MPCComplex(5.0,Inf)),MPCComplex(Inf,pi/2)) +@test isequal(asinh(MPCComplex(5.0,-Inf)),MPCComplex(Inf,-pi/2)) +@test isequal(asinh(MPCComplex(-5.0,Inf)),MPCComplex(-Inf,pi/2)) +@test isequal(asinh(MPCComplex(-5.0,-Inf)),MPCComplex(-Inf,-pi/2)) + +@test isequal(asinh(MPCComplex(0.0,NaN)),MPCComplex(NaN,NaN)) +@test isequal(asinh(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(asinh(MPCComplex(Inf,Inf)),MPCComplex(Inf,pi/4)) +@test isequal(asinh(MPCComplex(Inf,-Inf)),MPCComplex(Inf,-pi/4)) +@test isequal(asinh(MPCComplex(-Inf,Inf)),MPCComplex(-Inf,pi/4)) +@test isequal(asinh(MPCComplex(-Inf,-Inf)),MPCComplex(-Inf,-pi/4)) + +@test isequal(asinh(MPCComplex(Inf,NaN)),MPCComplex(Inf,NaN)) +@test isequal(asinh(MPCComplex(-Inf,NaN)),MPCComplex(-Inf,NaN)) + +@test isequal(asinh(MPCComplex(NaN,0.0)),MPCComplex(NaN,0.0)) +@test isequal(asinh(MPCComplex(NaN,-0.0)),MPCComplex(NaN,-0.0)) + +@test isequal(asinh(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) + +@test isequal(asinh(MPCComplex(NaN,Inf)),MPCComplex(Inf,NaN)) +@test isequal(asinh(MPCComplex(NaN,-Inf)),MPCComplex(Inf,NaN)) + +@test isequal(asinh(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + +# asin +# asin(z) = -i*asinh(iz) +@test isequal(asin(MPCComplex(0.0,0.0)),MPCComplex(0.0,0.0)) +@test isequal(asin(MPCComplex(0.0,-0.0)),MPCComplex(0.0,-0.0)) +@test isequal(asin(MPCComplex(-0.0,0.0)),MPCComplex(-0.0,0.0)) +@test isequal(asin(MPCComplex(-0.0,-0.0)),MPCComplex(-0.0,-0.0)) + +@test isequal(asin(MPCComplex(Inf,0.0)),MPCComplex(pi/2,Inf)) +@test isequal(asin(MPCComplex(-Inf,0.0)),MPCComplex(-pi/2,Inf)) +@test isequal(asin(MPCComplex(Inf,-0.0)),MPCComplex(pi/2,-Inf)) +@test isequal(asin(MPCComplex(-Inf,-0.0)),MPCComplex(-pi/2,-Inf)) + +@test isequal(asin(MPCComplex(Inf,5.0)),MPCComplex(pi/2,Inf)) +@test isequal(asin(MPCComplex(-Inf,5.0)),MPCComplex(-pi/2,Inf)) +@test isequal(asin(MPCComplex(Inf,-5.0)),MPCComplex(pi/2,-Inf)) +@test isequal(asin(MPCComplex(-Inf,-5.0)),MPCComplex(-pi/2,-Inf)) + +@test isequal(asin(MPCComplex(NaN,0.0)),MPCComplex(NaN,NaN)) +@test isequal(asin(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) + +@test isequal(asin(MPCComplex(Inf,Inf)),MPCComplex(pi/4,Inf)) +@test isequal(asin(MPCComplex(Inf,-Inf)),MPCComplex(pi/4,-Inf)) +@test isequal(asin(MPCComplex(-Inf,Inf)),MPCComplex(-pi/4,Inf)) +@test isequal(asin(MPCComplex(-Inf,-Inf)),MPCComplex(-pi/4,-Inf)) + +@test isequal(asin(MPCComplex(NaN,Inf)),MPCComplex(NaN,Inf)) +@test isequal(asin(MPCComplex(NaN,-Inf)),MPCComplex(NaN,-Inf)) + +@test isequal(asin(MPCComplex(0.0,NaN)),MPCComplex(0.0,NaN)) +@test isequal(asin(MPCComplex(-0.0,NaN)),MPCComplex(-0.0,NaN)) + +@test isequal(asin(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(asin(MPCComplex(Inf,NaN)),MPCComplex(NaN,Inf)) +@test isequal(asin(MPCComplex(-Inf,NaN)),MPCComplex(NaN,Inf)) + +@test isequal(asin(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + + +# atanh +# atanh(conj(z)) = conj(atanh(z)) +# atang(-z) = -atanh(z) + +@test isequal(atanh(MPCComplex(0.0,0.0)),MPCComplex(0.0,0.0)) +@test isequal(atanh(MPCComplex(0.0,-0.0)),MPCComplex(0.0,-0.0)) +@test isequal(atanh(MPCComplex(-0.0,0.0)),MPCComplex(-0.0,0.0)) +@test isequal(atanh(MPCComplex(-0.0,-0.0)),MPCComplex(-0.0,-0.0)) + +@test isequal(atanh(MPCComplex(0.0,NaN)),MPCComplex(0.0,NaN)) +@test isequal(atanh(MPCComplex(-0.0,NaN)),MPCComplex(-0.0,NaN)) + +# raise divide-by-zero flag +@test isequal(atanh(MPCComplex(1.0,0.0)),MPCComplex(Inf,0.0)) + +@test isequal(atanh(MPCComplex(0.0,Inf)),MPCComplex(0.0,pi/2)) +@test isequal(atanh(MPCComplex(0.0,-Inf)),MPCComplex(0.0,-pi/2)) +@test isequal(atanh(MPCComplex(-0.0,Inf)),MPCComplex(-0.0,pi/2)) +@test isequal(atanh(MPCComplex(-0.0,-Inf)),MPCComplex(-0.0,-pi/2)) + +@test isequal(atanh(MPCComplex(5.0,Inf)),MPCComplex(0.0,pi/2)) +@test isequal(atanh(MPCComplex(5.0,-Inf)),MPCComplex(0.0,-pi/2)) +@test isequal(atanh(MPCComplex(-5.0,Inf)),MPCComplex(-0.0,pi/2)) +@test isequal(atanh(MPCComplex(-5.0,-Inf)),MPCComplex(-0.0,-pi/2)) + +@test isequal(atanh(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) +@test isequal(atanh(MPCComplex(-5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(atanh(MPCComplex(Inf,0.0)),MPCComplex(0.0,pi/2)) +@test isequal(atanh(MPCComplex(Inf,-0.0)),MPCComplex(0.0,-pi/2)) +@test isequal(atanh(MPCComplex(-Inf,0.0)),MPCComplex(-0.0,pi/2)) +@test isequal(atanh(MPCComplex(-Inf,-0.0)),MPCComplex(-0.0,-pi/2)) + +@test isequal(atanh(MPCComplex(Inf,5.0)),MPCComplex(0.0,pi/2)) +@test isequal(atanh(MPCComplex(Inf,-5.0)),MPCComplex(0.0,-pi/2)) +@test isequal(atanh(MPCComplex(-Inf,5.0)),MPCComplex(-0.0,pi/2)) +@test isequal(atanh(MPCComplex(-Inf,-5.0)),MPCComplex(-0.0,-pi/2)) + +@test isequal(atanh(MPCComplex(Inf,Inf)),MPCComplex(0.0,pi/2)) +@test isequal(atanh(MPCComplex(Inf,-Inf)),MPCComplex(0.0,-pi/2)) +@test isequal(atanh(MPCComplex(-Inf,Inf)),MPCComplex(-0.0,pi/2)) +@test isequal(atanh(MPCComplex(-Inf,-Inf)),MPCComplex(-0.0,-pi/2)) + +@test isequal(atanh(MPCComplex(Inf,NaN)),MPCComplex(0.0,NaN)) +@test isequal(atanh(MPCComplex(-Inf,NaN)),MPCComplex(-0.0,NaN)) + +@test isequal(atanh(MPCComplex(NaN,0.0)),MPCComplex(NaN,NaN)) +@test isequal(atanh(MPCComplex(NaN,-0.0)),MPCComplex(NaN,NaN)) +@test isequal(atanh(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) +@test isequal(atanh(MPCComplex(NaN,-5.0)),MPCComplex(NaN,NaN)) + +@test isequal(atanh(MPCComplex(NaN,Inf)),MPCComplex(0.0,pi/2)) +@test isequal(atanh(MPCComplex(NaN,-Inf)),MPCComplex(0.0,-pi/2)) + +@test isequal(atanh(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + + +# atan +# atan(z) = -i*tanh(iz) + +@test isequal(atan(MPCComplex(0.0,0.0)),MPCComplex(0.0,0.0)) +@test isequal(atan(MPCComplex(0.0,-0.0)),MPCComplex(0.0,-0.0)) +@test isequal(atan(MPCComplex(-0.0,0.0)),MPCComplex(-0.0,0.0)) +@test isequal(atan(MPCComplex(-0.0,-0.0)),MPCComplex(-0.0,-0.0)) + +@test isequal(atan(MPCComplex(NaN,0.0)),MPCComplex(NaN,0.0)) +@test isequal(atan(MPCComplex(NaN,-0.0)),MPCComplex(NaN,-0.0)) + +# raise divide-by-zero flag +@test isequal(atan(MPCComplex(0.0,1.0)),MPCComplex(0.0,Inf)) + +@test isequal(atan(MPCComplex(Inf,0.0)),MPCComplex(pi/2,0.0)) +@test isequal(atan(MPCComplex(-Inf,0.0)),MPCComplex(-pi/2,0.0)) +@test isequal(atan(MPCComplex(Inf,-0.0)),MPCComplex(pi/2,-0.0)) +@test isequal(atan(MPCComplex(-Inf,-0.0)),MPCComplex(-pi/2,-0.0)) + +@test isequal(atan(MPCComplex(Inf,5.0)),MPCComplex(pi/2,0.0)) +@test isequal(atan(MPCComplex(-Inf,5.0)),MPCComplex(-pi/2,0.0)) +@test isequal(atan(MPCComplex(Inf,-5.0)),MPCComplex(pi/2,-0.0)) +@test isequal(atan(MPCComplex(-Inf,-5.0)),MPCComplex(-pi/2,-0.0)) + +@test isequal(atan(MPCComplex(NaN,5.0)),MPCComplex(NaN,NaN)) +@test isequal(atan(MPCComplex(NaN,-5.0)),MPCComplex(NaN,NaN)) + +@test isequal(atan(MPCComplex(0.0,Inf)),MPCComplex(pi/2,0.0)) +@test isequal(atan(MPCComplex(-0.0,Inf)),MPCComplex(-pi/2,0.0)) +@test isequal(atan(MPCComplex(0.0,-Inf)),MPCComplex(pi/2,-0.0)) +@test isequal(atan(MPCComplex(-0.0,-Inf)),MPCComplex(-pi/2,-0.0)) + +@test isequal(atan(MPCComplex(5.0,Inf)),MPCComplex(pi/2,0.0)) +@test isequal(atan(MPCComplex(-5.0,Inf)),MPCComplex(-pi/2,0.0)) +@test isequal(atan(MPCComplex(5.0,-Inf)),MPCComplex(pi/2,-0.0)) +@test isequal(atan(MPCComplex(-5.0,-Inf)),MPCComplex(-pi/2,-0.0)) + +@test isequal(atan(MPCComplex(Inf,Inf)),MPCComplex(pi/2,0.0)) +@test isequal(atan(MPCComplex(Inf,-Inf)),MPCComplex(pi/2,-0.0)) +@test isequal(atan(MPCComplex(-Inf,Inf)),MPCComplex(-pi/2,0.0)) +@test isequal(atan(MPCComplex(-Inf,-Inf)),MPCComplex(-pi/2,-0.0)) + +@test isequal(atan(MPCComplex(NaN,Inf)),MPCComplex(NaN,0.0)) +@test isequal(atan(MPCComplex(NaN,-Inf)),MPCComplex(NaN,-0.0)) + +@test isequal(atan(MPCComplex(0.0,NaN)),MPCComplex(NaN,NaN)) +@test isequal(atan(MPCComplex(-0.0,NaN)),MPCComplex(NaN,NaN)) +@test isequal(atan(MPCComplex(5.0,NaN)),MPCComplex(NaN,NaN)) +@test isequal(atan(MPCComplex(-5.0,NaN)),MPCComplex(NaN,NaN)) + +@test isequal(atan(MPCComplex(Inf,NaN)),MPCComplex(pi/2,0.0)) +@test isequal(atan(MPCComplex(-Inf,NaN)),MPCComplex(-pi/2,0.0)) + +@test isequal(atan(MPCComplex(NaN,NaN)),MPCComplex(NaN,NaN)) + +end # end precision change