@@ -32,6 +32,7 @@ def test_binary_ops(op, other):
3232 quad_result = op_func (quad_a , quad_b )
3333 float_result = op_func (float_a , float_b )
3434
35+ # FIXME: @juntyr: replace with array_equal once isnan is supported
3536 with np .errstate (invalid = "ignore" ):
3637 assert (
3738 (np .float64 (quad_result ) == float_result ) or
@@ -106,31 +107,30 @@ def test_array_aminmax(op, a, b):
106107 assert np .all ((quad_res == float_res ) | ((quad_res != quad_res ) & (float_res != float_res )))
107108
108109
109- @pytest .mark .parametrize ("op, val, expected" , [
110- ("neg" , "3.0" , "-3.0" ),
111- ("neg" , "-3.0" , "3.0" ),
112- ("pos" , "3.0" , "3.0" ),
113- ("pos" , "-3.0" , "-3.0" ),
114- ("abs" , "3.0" , "3.0" ),
115- ("abs" , "-3.0" , "3.0" ),
116- ("neg" , "12.5" , "-12.5" ),
117- ("pos" , "100.0" , "100.0" ),
118- ("abs" , "-25.5" , "25.5" ),
119- ])
120- def test_unary_ops (op , val , expected ):
110+ @pytest .mark .parametrize ("op,nop" , [("neg" , "negative" ), ("pos" , "positive" ), ("abs" , "absolute" ), (None , "sign" )])
111+ @pytest .mark .parametrize ("val" , ["3.0" , "-3.0" , "12.5" , "100.0" , "0.0" , "-0.0" , "inf" , "-inf" , "nan" , "-nan" ])
112+ def test_unary_ops (op , nop , val ):
113+ op_func = None if op is None else getattr (operator , op )
114+ nop_func = getattr (np , nop )
115+
121116 quad_val = QuadPrecision (val )
122- expected_val = QuadPrecision (expected )
123-
124- if op == "neg" :
125- result = - quad_val
126- elif op == "pos" :
127- result = + quad_val
128- elif op == "abs" :
129- result = abs (quad_val )
130- else :
131- raise ValueError (f"Unsupported operation: { op } " )
132-
133- assert result == expected_val , f"{ op } ({ val } ) should be { expected } , but got { result } "
117+ float_val = float (val )
118+
119+ for op_func in [op_func , nop_func ]:
120+ if op_func is None :
121+ continue
122+
123+ quad_result = op_func (quad_val )
124+ float_result = op_func (float_val )
125+
126+ # FIXME: @juntyr: replace with array_equal once isnan is supported
127+ # FIXME: @juntyr: also check the signbit once that is supported
128+ with np .errstate (invalid = "ignore" ):
129+ assert (
130+ (np .float64 (quad_result ) == float_result ) or
131+ ((float_result != float_result ) and (quad_result != quad_result ))
132+ ), f"{ op } ({ val } ) should be { float_result } , but got { quad_result } "
133+
134134
135135def test_inf ():
136136 assert QuadPrecision ("inf" ) > QuadPrecision ("1e1000" )
0 commit comments