@@ -4,9 +4,22 @@ using LinearAlgebra
4
4
5
5
@test reim (2 + 3im ) == (2 , 3 )
6
6
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
+
7
18
for T in (Int64, Float64)
8
19
@test real (T) == T
9
20
@test real (Complex{T}) == T
21
+ # TestQuaternions are neither real or complex
22
+ @test real (TestQuaternion{T}) == T
10
23
@test complex (T) == Complex{T}
11
24
@test complex (Complex{T}) == Complex{T}
12
25
end
737
750
@test isequal (atanh (complex ( Inf , Inf )),complex (0.0 , pi / 2 ))
738
751
@test isequal (atanh (complex ( Inf ,- Inf )),complex (0.0 ,- pi / 2 ))
739
752
@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 ))
740
755
741
756
@test isequal (atanh (complex (- Inf , 0.0 )),complex (- 0.0 , pi / 2 ))
742
757
@test isequal (atanh (complex (- Inf ,- 0.0 )),complex (- 0.0 ,- pi / 2 ))
978
993
@test log1p (z) ≈ log (1 + z)
979
994
@test exp2 (z) ≈ exp (z * log (2 ))
980
995
@test exp10 (z) ≈ exp (z * log (10 ))
996
+ @test isequal (z^ true , z)
997
+ @test isequal (z^ 0 , complex (1.0 ,0.0 ))
981
998
end
982
999
end
983
1000
@@ -1049,6 +1066,18 @@ end
1049
1066
@test isequal (one (T) / complex (- zero (T), T (- Inf )), complex (- zero (T), zero (T)))
1050
1067
@test isequal (one (T) / complex (- one (T), T (- Inf )), complex (- zero (T), zero (T)))
1051
1068
@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
1052
1081
end
1053
1082
end
1054
1083
@@ -1152,3 +1181,6 @@ end
1152
1181
1153
1182
# real(C) with C a Complex Unionall
1154
1183
@test real (Complex{<: AbstractFloat }) == AbstractFloat
1184
+
1185
+ # complex with non-concrete eltype
1186
+ @test_throws ErrorException complex (Union{Complex{Int}, Nothing}[])
0 commit comments