@@ -18,8 +18,11 @@ def test_basic_equality():
18
18
19
19
20
20
@pytest .mark .parametrize ("op" , ["add" , "sub" , "mul" , "truediv" , "pow" ])
21
- @pytest .mark .parametrize ("other" , ["3.0" , "12.5" , "100.0" ])
21
+ @pytest .mark .parametrize ("other" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
22
22
def test_binary_ops (op , other ):
23
+ if op == "truediv" and float (other ) == 0 :
24
+ pytest .xfail ("float division by zero" )
25
+
23
26
op_func = getattr (operator , op )
24
27
quad_a = QuadPrecision ("12.5" )
25
28
quad_b = QuadPrecision (other )
@@ -29,21 +32,80 @@ def test_binary_ops(op, other):
29
32
quad_result = op_func (quad_a , quad_b )
30
33
float_result = op_func (float_a , float_b )
31
34
32
- assert np .abs (np .float64 (quad_result ) - float_result ) < 1e-10
35
+ with np .errstate (invalid = "ignore" ):
36
+ assert (
37
+ (np .float64 (quad_result ) == float_result ) or
38
+ (np .abs (np .float64 (quad_result ) - float_result ) < 1e-10 ) or
39
+ ((float_result != float_result ) and (quad_result != quad_result ))
40
+ )
33
41
34
42
35
43
@pytest .mark .parametrize ("op" , ["eq" , "ne" , "le" , "lt" , "ge" , "gt" ])
36
- @pytest .mark .parametrize ("other" , ["3.0" , "12.5" , "100.0" ])
37
- def test_comparisons (op , other ):
44
+ @pytest .mark .parametrize ("a" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
45
+ @pytest .mark .parametrize ("b" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
46
+ def test_comparisons (op , a , b ):
38
47
op_func = getattr (operator , op )
39
- quad_a = QuadPrecision ("12.5" )
40
- quad_b = QuadPrecision (other )
41
- float_a = 12.5
42
- float_b = float (other )
48
+ quad_a = QuadPrecision (a )
49
+ quad_b = QuadPrecision (b )
50
+ float_a = float ( a )
51
+ float_b = float (b )
43
52
44
53
assert op_func (quad_a , quad_b ) == op_func (float_a , float_b )
45
54
46
55
56
+ @pytest .mark .parametrize ("op" , ["eq" , "ne" , "le" , "lt" , "ge" , "gt" ])
57
+ @pytest .mark .parametrize ("a" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
58
+ @pytest .mark .parametrize ("b" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
59
+ def test_array_comparisons (op , a , b ):
60
+ op_func = getattr (operator , op )
61
+ quad_a = np .array (QuadPrecision (a ))
62
+ quad_b = np .array (QuadPrecision (b ))
63
+ float_a = np .array (float (a ))
64
+ float_b = np .array (float (b ))
65
+
66
+ assert np .array_equal (op_func (quad_a , quad_b ), op_func (float_a , float_b ))
67
+
68
+
69
+ @pytest .mark .parametrize ("op" , ["minimum" , "maximum" , "fmin" , "fmax" ])
70
+ @pytest .mark .parametrize ("a" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
71
+ @pytest .mark .parametrize ("b" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
72
+ def test_array_minmax (op , a , b ):
73
+ if op in ["fmin" , "fmax" ]:
74
+ pytest .skip ("fmin and fmax ufuncs are not yet supported" )
75
+
76
+ op_func = getattr (np , op )
77
+ quad_a = np .array ([QuadPrecision (a )])
78
+ quad_b = np .array ([QuadPrecision (b )])
79
+ float_a = np .array ([float (a )])
80
+ float_b = np .array ([float (b )])
81
+
82
+ quad_res = op_func (quad_a , quad_b )
83
+ float_res = op_func (float_a , float_b )
84
+
85
+ # FIXME: @juntyr: replace with array_equal once isnan is supported
86
+ with np .errstate (invalid = "ignore" ):
87
+ assert np .all ((quad_res == float_res ) | ((quad_res != quad_res ) & (float_res != float_res )))
88
+
89
+
90
+ @pytest .mark .parametrize ("op" , ["amin" , "amax" , "nanmin" , "nanmax" ])
91
+ @pytest .mark .parametrize ("a" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
92
+ @pytest .mark .parametrize ("b" , ["3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
93
+ def test_array_aminmax (op , a , b ):
94
+ if op in ["nanmin" , "nanmax" ]:
95
+ pytest .skip ("fmin and fmax ufuncs are not yet supported" )
96
+
97
+ op_func = getattr (np , op )
98
+ quad_ab = np .array ([QuadPrecision (a ), QuadPrecision (b )])
99
+ float_ab = np .array ([float (a ), float (b )])
100
+
101
+ quad_res = op_func (quad_ab )
102
+ float_res = op_func (float_ab )
103
+
104
+ # FIXME: @juntyr: replace with array_equal once isnan is supported
105
+ with np .errstate (invalid = "ignore" ):
106
+ assert np .all ((quad_res == float_res ) | ((quad_res != quad_res ) & (float_res != float_res )))
107
+
108
+
47
109
@pytest .mark .parametrize ("op, val, expected" , [
48
110
("neg" , "3.0" , "-3.0" ),
49
111
("neg" , "-3.0" , "3.0" ),
0 commit comments