1
1
using NaNMath
2
2
using Test
3
+ using DoubleFloats
4
+
5
+
6
+ # https://github.com/JuliaMath/NaNMath.jl/issues/76
7
+ @test_throws MethodError NaNMath. pow (1.0 , 1.0 + im)
8
+
9
+
10
+ for T in (Float64, Float32, Float16, BigFloat)
11
+ for f in (:sin , :cos , :tan , :asin , :acos , :acosh , :atanh , :log , :log2 , :log10 ,
12
+ :log1p ) # Note: do :lgamma separately because it can't handle BigFloat
13
+ @eval begin
14
+ @test NaNMath.$ f ($ T (2 // 3 )) isa $ T
15
+ @test NaNMath.$ f ($ T (3 // 2 )) isa $ T
16
+ @test NaNMath.$ f ($ T (- 2 // 3 )) isa $ T
17
+ @test NaNMath.$ f ($ T (- 3 // 2 )) isa $ T
18
+ @test NaNMath.$ f ($ T (Inf )) isa $ T
19
+ @test NaNMath.$ f ($ T (- Inf )) isa $ T
20
+ end
21
+ end
22
+ end
23
+ for T in (Float64, Float32, Float16)
24
+ @test NaNMath. lgamma (T (2 // 3 )) isa T
25
+ @test NaNMath. lgamma (T (3 // 2 )) isa T
26
+ @test NaNMath. lgamma (T (- 2 // 3 )) isa T
27
+ @test NaNMath. lgamma (T (- 3 // 2 )) isa T
28
+ @test NaNMath. lgamma (T (Inf )) isa T
29
+ @test NaNMath. lgamma (T (- Inf )) isa T
30
+ end
31
+ @test_throws MethodError NaNMath. lgamma (BigFloat (2 // 3 ))
3
32
4
33
@test isnan (NaNMath. log (- 10 ))
34
+ @test isnan (NaNMath. log (- 10f0 ))
35
+ @test isnan (NaNMath. log (Float16 (- 10 )))
5
36
@test isnan (NaNMath. log1p (- 100 ))
37
+ @test isnan (NaNMath. log1p (- 100f0 ))
38
+ @test isnan (NaNMath. log1p (Float16 (- 100 )))
6
39
@test isnan (NaNMath. pow (- 1.5 ,2.3 ))
7
40
@test isnan (NaNMath. pow (- 1.5f0 ,2.3f0 ))
8
41
@test isnan (NaNMath. pow (- 1.5 ,2.3f0 ))
9
42
@test isnan (NaNMath. pow (- 1.5f0 ,2.3 ))
43
+ @test isnan (NaNMath. pow (Float16 (- 1.5 ),Float16 (2.3 )))
44
+ @test isnan (NaNMath. pow (Float16 (- 1.5 ),2.3 ))
45
+ @test isnan (NaNMath. pow (- 1.5 ,Float16 (2.3 )))
46
+ @test isnan (NaNMath. pow (Float16 (- 1.5 ),2.3f0 ))
47
+ @test isnan (NaNMath. pow (- 1.5f0 ,Float16 (2.3 )))
48
+ @test isnan (NaNMath. pow (- 1.5f0 ,BigFloat (2.3 )))
49
+ @test isnan (NaNMath. pow (BigFloat (- 1.5 ),BigFloat (2.3 )))
50
+ @test isnan (NaNMath. pow (BigFloat (- 1.5 ),2.3f0 ))
51
+ @test isnan (NaNMath. pow (- 1.5f0 ,Double64 (2.3 )))
52
+ @test isnan (NaNMath. pow (Double64 (- 1.5 ),Double64 (2.3 )))
53
+ @test isnan (NaNMath. pow (Double64 (- 1.5 ),2.3f0 ))
10
54
@test NaNMath. pow (- 1 ,2 ) isa Float64
11
55
@test NaNMath. pow (- 1.5f0 ,2 ) isa Float32
12
56
@test NaNMath. pow (- 1.5f0 ,2 // 1 ) isa Float32
@@ -16,11 +60,28 @@ using Test
16
60
@test NaNMath. pow (- 1.5 ,2 // 1 ) isa Float64
17
61
@test NaNMath. pow (- 1.5 ,2.3f0 ) isa Float64
18
62
@test NaNMath. pow (- 1.5 ,2.3 ) isa Float64
19
- @test isnan (NaNMath. sqrt (- 5 ))
63
+ @test NaNMath. pow (Float16 (- 1.5 ),2.3 ) isa Float64
64
+ @test NaNMath. pow (Float16 (- 1.5 ),Float16 (2.3 )) isa Float16
65
+ @test NaNMath. pow (- 1.5 ,Float16 (2.3 )) isa Float64
66
+ @test NaNMath. pow (Float16 (- 1.5 ),2.3f0 ) isa Float32
67
+ @test NaNMath. pow (- 1.5f0 ,Float16 (2.3 )) isa Float32
68
+ @test NaNMath. pow (- 1.5f0 ,BigFloat (2.3 )) isa BigFloat
69
+ @test NaNMath. pow (BigFloat (- 1.5 ),BigFloat (2.3 )) isa BigFloat
70
+ @test NaNMath. pow (BigFloat (- 1.5 ),2.3f0 ) isa BigFloat
71
+ @test NaNMath. pow (- 1.5f0 ,Double64 (2.3 )) isa Double64
72
+ @test NaNMath. pow (Double64 (- 1.5 ),Double64 (2.3 )) isa Double64
73
+ @test NaNMath. pow (Double64 (- 1.5 ),2.3f0 ) isa Double64
74
+ @test NaNMath. sqrt (- 5 ) isa Float64
20
75
@test NaNMath. sqrt (5 ) == Base. sqrt (5 )
76
+ @test NaNMath. sqrt (- 5f0 ) isa Float32
77
+ @test NaNMath. sqrt (5f0 ) == Base. sqrt (5f0 )
78
+ @test NaNMath. sqrt (Float16 (- 5 )) isa Float16
79
+ @test NaNMath. sqrt (Float16 (5 )) == Base. sqrt (Float16 (5 ))
80
+ @test NaNMath. sqrt (BigFloat (- 5 )) isa BigFloat
81
+ @test NaNMath. sqrt (BigFloat (5 )) == Base. sqrt (BigFloat (5 ))
21
82
@test isnan (NaNMath. sqrt (- 3.2f0 )) && NaNMath. sqrt (- 3.2f0 ) isa Float32
22
- @test isnan (NaNMath. sqrt (- BigFloat (7.0 ))) && NaNMath. sqrt (- BigFloat (7.0 )) isa BigFloat
23
- @test isnan (NaNMath. sqrt (- 7 )) && NaNMath. sqrt (- 7 ) isa Float64
83
+ @test isnan (NaNMath. sqrt (- BigFloat (7.0 ))) && NaNMath. sqrt (- BigFloat (7.0 )) isa BigFloat
84
+ @test isnan (NaNMath. sqrt (- 7 )) && NaNMath. sqrt (- 7 ) isa Float64
24
85
@inferred NaNMath. sqrt (5 )
25
86
@inferred NaNMath. sqrt (5.0 )
26
87
@inferred NaNMath. sqrt (5.0f0 )
0 commit comments