@@ -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,12 +32,17 @@ 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 ("a" , ["3.0" , "12.5" , "100.0" , "inf" , "-inf" , "nan" , "-nan" ])
37
- @pytest .mark .parametrize ("b" , ["3.0" , "12.5" , "100.0" , "inf" , "-inf" , "nan" , "-nan" ])
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" ])
38
46
def test_comparisons (op , a , b ):
39
47
op_func = getattr (operator , op )
40
48
quad_a = QuadPrecision (a )
@@ -46,8 +54,8 @@ def test_comparisons(op, a, b):
46
54
47
55
48
56
@pytest .mark .parametrize ("op" , ["eq" , "ne" , "le" , "lt" , "ge" , "gt" ])
49
- @pytest .mark .parametrize ("a" , ["3.0" , "12.5" , "100.0" , "inf" , "-inf" , "nan" , "-nan" ])
50
- @pytest .mark .parametrize ("b" , ["3.0" , "12.5" , "100.0" , "inf" , "-inf" , "nan" , "-nan" ])
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" ])
51
59
def test_array_comparisons (op , a , b ):
52
60
op_func = getattr (operator , op )
53
61
quad_a = np .array (QuadPrecision (a ))
@@ -58,6 +66,46 @@ def test_array_comparisons(op, a, b):
58
66
assert np .array_equal (op_func (quad_a , quad_b ), op_func (float_a , float_b ))
59
67
60
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
+
61
109
@pytest .mark .parametrize ("op, val, expected" , [
62
110
("neg" , "3.0" , "-3.0" ),
63
111
("neg" , "-3.0" , "3.0" ),
0 commit comments