Skip to content

Commit 6959a0c

Browse files
bramtaylKeno
authored andcommitted
Missing complex tests (#34446)
1 parent 046dfb0 commit 6959a0c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/complex.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@ using LinearAlgebra
44

55
@test reim(2 + 3im) == (2, 3)
66

7+
import Base: zero, real
8+
struct TestQuaternion{T} <: Number
9+
scalar::T
10+
i_component::T
11+
j_component::T
12+
k_component::T
13+
end
14+
zero(::Type{TestQuaternion{T}}) where {T} =
15+
TestQuaternion(zero(T), zero(T), zero(T), zero(T))
16+
real(quaternion::TestQuaternion) = quaternion.scalar
17+
718
for T in (Int64, Float64)
819
@test real(T) == T
920
@test real(Complex{T}) == T
21+
# TestQuaternions are neither real or complex
22+
@test real(TestQuaternion{T}) == T
1023
@test complex(T) == Complex{T}
1124
@test complex(Complex{T}) == Complex{T}
1225
end
@@ -737,6 +750,8 @@ end
737750
@test isequal(atanh(complex( Inf, Inf)),complex(0.0, pi/2))
738751
@test isequal(atanh(complex( Inf,-Inf)),complex(0.0,-pi/2))
739752
@test isequal(atanh(complex( Inf, NaN)),complex(0.0, NaN))
753+
# very big but not infinite
754+
@test isequal(atanh(complex(4e200, NaN)),complex(NaN, NaN))
740755

741756
@test isequal(atanh(complex(-Inf, 0.0)),complex(-0.0, pi/2))
742757
@test isequal(atanh(complex(-Inf,-0.0)),complex(-0.0,-pi/2))
@@ -978,6 +993,8 @@ end
978993
@test log1p(z) log(1 + z)
979994
@test exp2(z) exp(z * log(2))
980995
@test exp10(z) exp(z * log(10))
996+
@test isequal(z^true, z)
997+
@test isequal(z^0, complex(1.0,0.0))
981998
end
982999
end
9831000

@@ -1049,6 +1066,18 @@ end
10491066
@test isequal(one(T) / complex(-zero(T), T(-Inf)), complex(-zero(T), zero(T)))
10501067
@test isequal(one(T) / complex(-one(T), T(-Inf)), complex(-zero(T), zero(T)))
10511068
@test isequal(one(T) / complex(T(-NaN), T(-Inf)), complex(-zero(T), zero(T)))
1069+
1070+
# divide complex by complex Inf
1071+
if T == Float64
1072+
@test_broken isequal(complex(one(T)) / complex(T(Inf), T(-Inf)), complex(zero(T), zero(T)))
1073+
@test_broken isequal(complex(one(T)) / complex(T(-Inf), T(Inf)), complex(-zero(T), -zero(T)))
1074+
elseif T == Float32
1075+
@test isequal(complex(one(T)) / complex(T(Inf), T(-Inf)), complex(zero(T), zero(T)))
1076+
@test_broken isequal(complex(one(T)) / complex(T(-Inf), T(Inf)), complex(-zero(T), -zero(T)))
1077+
else
1078+
@test isequal(complex(one(T)) / complex(T(Inf), T(-Inf)), complex(zero(T), zero(T)))
1079+
@test isequal(complex(one(T)) / complex(T(-Inf), T(Inf)), complex(-zero(T), -zero(T)))
1080+
end
10521081
end
10531082
end
10541083

@@ -1152,3 +1181,6 @@ end
11521181

11531182
# real(C) with C a Complex Unionall
11541183
@test real(Complex{<:AbstractFloat}) == AbstractFloat
1184+
1185+
# complex with non-concrete eltype
1186+
@test_throws ErrorException complex(Union{Complex{Int}, Nothing}[])

0 commit comments

Comments
 (0)