@@ -1552,4 +1552,42 @@ def test_float_power_array():
15521552
15531553 assert result .dtype .name == "QuadPrecDType128"
15541554 for i in range (len (result )):
1555- np .testing .assert_allclose (float (result [i ]), expected [i ], rtol = 1e-13 )
1555+ np .testing .assert_allclose (float (result [i ]), expected [i ], rtol = 1e-13 )
1556+
1557+
1558+ @pytest .mark .parametrize ("val" , [
1559+ # Positive values
1560+ "3.0" , "12.5" , "100.0" , "1e100" , "0.0" ,
1561+ # Negative values
1562+ "-3.0" , "-12.5" , "-100.0" , "-1e100" , "-0.0" ,
1563+ # Special values
1564+ "inf" , "-inf" , "nan" , "-nan" ,
1565+ # Small values
1566+ "1e-100" , "-1e-100"
1567+ ])
1568+ def test_fabs (val ):
1569+ """
1570+ Test np.fabs ufunc for QuadPrecision dtype.
1571+ fabs computes absolute values (positive magnitude) for floating-point numbers.
1572+ It should behave identically to np.absolute for real (non-complex) types.
1573+ """
1574+ quad_val = QuadPrecision (val )
1575+ float_val = float (val )
1576+
1577+ quad_result = np .fabs (quad_val )
1578+ float_result = np .fabs (float_val )
1579+
1580+ # Test with both scalar and array
1581+ quad_arr = np .array ([quad_val ], dtype = QuadPrecDType ())
1582+ quad_arr_result = np .fabs (quad_arr )
1583+
1584+ # Check scalar result
1585+ np .testing .assert_array_equal (np .array (quad_result ).astype (float ), float_result )
1586+
1587+ # Check array result
1588+ np .testing .assert_array_equal (quad_arr_result .astype (float )[0 ], float_result )
1589+
1590+ # For zero results, check sign (should always be positive after fabs)
1591+ if float_result == 0.0 :
1592+ assert not np .signbit (quad_result ), f"fabs({ val } ) should not have negative sign"
1593+ assert not np .signbit (quad_arr_result [0 ]), f"fabs({ val } ) should not have negative sign"
0 commit comments