@@ -253,6 +253,81 @@ def test_rint_near_halfway():
253253 assert np .rint (QuadPrecision ("7.5" )) == 8
254254
255255
256+ @pytest .mark .parametrize ("val" , [
257+ # Perfect cubes
258+ "1.0" , "8.0" , "27.0" , "64.0" , "125.0" , "1000.0" ,
259+ # Negative perfect cubes
260+ "-1.0" , "-8.0" , "-27.0" , "-64.0" , "-125.0" , "-1000.0" ,
261+ # Small positive values
262+ "0.001" , "0.008" , "0.027" , "1e-9" , "1e-15" , "1e-100" ,
263+ # Small negative values
264+ "-0.001" , "-0.008" , "-0.027" , "-1e-9" , "-1e-15" , "-1e-100" ,
265+ # Large positive values
266+ "1e10" , "1e15" , "1e100" , "1e300" ,
267+ # Large negative values
268+ "-1e10" , "-1e15" , "-1e100" , "-1e300" ,
269+ # Fractional values
270+ "0.5" , "2.5" , "3.5" , "10.5" , "100.5" ,
271+ "-0.5" , "-2.5" , "-3.5" , "-10.5" , "-100.5" ,
272+ # Edge cases
273+ "0.0" , "-0.0" ,
274+ # Special values
275+ "inf" , "-inf" , "nan" , "-nan"
276+ ])
277+ def test_cbrt (val ):
278+ """Comprehensive test for cube root function"""
279+ quad_val = QuadPrecision (val )
280+ float_val = float (val )
281+
282+ quad_result = np .cbrt (quad_val )
283+ float_result = np .cbrt (float_val )
284+
285+ # Handle NaN cases
286+ if np .isnan (float_result ):
287+ assert np .isnan (
288+ float (quad_result )), f"Expected NaN for cbrt({ val } ), got { float (quad_result )} "
289+ return
290+
291+ # Handle infinity cases
292+ if np .isinf (float_result ):
293+ assert np .isinf (
294+ float (quad_result )), f"Expected inf for cbrt({ val } ), got { float (quad_result )} "
295+ assert np .sign (float_result ) == np .sign (
296+ float (quad_result )), f"Infinity sign mismatch for cbrt({ val } )"
297+ return
298+
299+ # For finite results, check value and sign
300+ # Use relative tolerance for cbrt
301+ if float_result != 0.0 :
302+ rtol = 1e-14 if abs (float_result ) < 1e100 else 1e-10
303+ np .testing .assert_allclose (float (quad_result ), float_result , rtol = rtol , atol = 1e-15 ,
304+ err_msg = f"Value mismatch for cbrt({ val } )" )
305+ else :
306+ # For zero results
307+ assert float (quad_result ) == 0.0 , f"Expected 0 for cbrt({ val } ), got { float (quad_result )} "
308+ assert np .signbit (float_result ) == np .signbit (
309+ quad_result ), f"Zero sign mismatch for cbrt({ val } )"
310+
311+
312+ def test_cbrt_accuracy ():
313+ """Test that cbrt gives accurate results for perfect cubes"""
314+ # Test perfect cubes
315+ for i in [1 , 2 , 3 , 4 , 5 , 10 , 100 ]:
316+ val = QuadPrecision (i ** 3 )
317+ result = np .cbrt (val )
318+ expected = QuadPrecision (i )
319+ np .testing .assert_allclose (float (result ), float (expected ), rtol = 1e-14 , atol = 1e-15 ,
320+ err_msg = f"cbrt({ i } ^3) should equal { i } " )
321+
322+ # Test negative perfect cubes
323+ for i in [1 , 2 , 3 , 4 , 5 , 10 , 100 ]:
324+ val = QuadPrecision (- (i ** 3 ))
325+ result = np .cbrt (val )
326+ expected = QuadPrecision (- i )
327+ np .testing .assert_allclose (float (result ), float (expected ), rtol = 1e-14 , atol = 1e-15 ,
328+ err_msg = f"cbrt(-{ i } ^3) should equal -{ i } " )
329+
330+
256331@pytest .mark .parametrize ("op" , ["exp" , "exp2" ])
257332@pytest .mark .parametrize ("val" , [
258333 # Basic cases
0 commit comments