@@ -573,6 +573,8 @@ def testFloor(self):
573573 #self.assertEqual(math.ceil(NINF), NINF)
574574 #self.assertTrue(math.isnan(math.floor(NAN)))
575575
576+ class TestFloorIsNone (float ):
577+ __floor__ = None
576578 class TestFloor :
577579 def __floor__ (self ):
578580 return 42
@@ -588,6 +590,7 @@ class TestBadFloor:
588590 self .assertEqual (math .floor (FloatLike (41.9 )), 41 )
589591 self .assertRaises (TypeError , math .floor , TestNoFloor ())
590592 self .assertRaises (ValueError , math .floor , TestBadFloor ())
593+ self .assertRaises (TypeError , math .floor , TestFloorIsNone (3.5 ))
591594
592595 t = TestNoFloor ()
593596 t .__floor__ = lambda * args : args
@@ -1125,6 +1128,15 @@ def __index__(self):
11251128 with self .assertRaises (TypeError ):
11261129 math .isqrt (value )
11271130
1131+ @support .bigmemtest (2 ** 32 , memuse = 0.85 )
1132+ def test_isqrt_huge (self , size ):
1133+ if size & 1 :
1134+ size += 1
1135+ v = 1 << size
1136+ w = math .isqrt (v )
1137+ self .assertEqual (w .bit_length (), size // 2 + 1 )
1138+ self .assertEqual (w .bit_count (), 1 )
1139+
11281140 def test_lcm (self ):
11291141 lcm = math .lcm
11301142 self .assertEqual (lcm (0 , 0 ), 0 )
@@ -1272,6 +1284,13 @@ def testLog10(self):
12721284 self .assertEqual (math .log (INF ), INF )
12731285 self .assertTrue (math .isnan (math .log10 (NAN )))
12741286
1287+ @support .bigmemtest (2 ** 32 , memuse = 0.2 )
1288+ def test_log_huge_integer (self , size ):
1289+ v = 1 << size
1290+ self .assertAlmostEqual (math .log2 (v ), size )
1291+ self .assertAlmostEqual (math .log (v ), size * 0.6931471805599453 )
1292+ self .assertAlmostEqual (math .log10 (v ), size * 0.3010299956639812 )
1293+
12751294 def testSumProd (self ):
12761295 sumprod = math .sumprod
12771296 Decimal = decimal .Decimal
@@ -1380,7 +1399,6 @@ def test_sumprod_accuracy(self):
13801399 self .assertEqual (sumprod ([True , False ] * 10 , [0.1 ] * 20 ), 1.0 )
13811400 self .assertEqual (sumprod ([1.0 , 10E100 , 1.0 , - 10E100 ], [1.0 ]* 4 ), 2.0 )
13821401
1383- @unittest .skip ("TODO: RUSTPYTHON, Taking a few minutes." )
13841402 @support .requires_resource ('cpu' )
13851403 def test_sumprod_stress (self ):
13861404 sumprod = math .sumprod
@@ -2020,7 +2038,6 @@ def test_exceptions(self):
20202038 else :
20212039 self .fail ("sqrt(-1) didn't raise ValueError" )
20222040
2023- @unittest .expectedFailure # TODO: RUSTPYTHON
20242041 @requires_IEEE_754
20252042 def test_testfile (self ):
20262043 # Some tests need to be skipped on ancient OS X versions.
@@ -2495,6 +2512,46 @@ def test_input_exceptions(self):
24952512 self .assertRaises (TypeError , math .atan2 , 1.0 )
24962513 self .assertRaises (TypeError , math .atan2 , 1.0 , 2.0 , 3.0 )
24972514
2515+ def test_exception_messages (self ):
2516+ x = - 1.1
2517+ with self .assertRaisesRegex (ValueError ,
2518+ f"expected a nonnegative input, got { x } " ):
2519+ math .sqrt (x )
2520+ with self .assertRaisesRegex (ValueError ,
2521+ f"expected a positive input, got { x } " ):
2522+ math .log (x )
2523+ with self .assertRaisesRegex (ValueError ,
2524+ f"expected a positive input, got { x } " ):
2525+ math .log (123 , x )
2526+ with self .assertRaisesRegex (ValueError ,
2527+ f"expected a positive input, got { x } " ):
2528+ math .log (x , 123 )
2529+ with self .assertRaisesRegex (ValueError ,
2530+ f"expected a positive input, got { x } " ):
2531+ math .log2 (x )
2532+ with self .assertRaisesRegex (ValueError ,
2533+ f"expected a positive input, got { x } " ):
2534+ math .log10 (x )
2535+ x = decimal .Decimal ('-1.1' )
2536+ with self .assertRaisesRegex (ValueError ,
2537+ f"expected a positive input, got { x } " ):
2538+ math .log (x )
2539+ x = fractions .Fraction (1 , 10 ** 400 )
2540+ with self .assertRaisesRegex (ValueError ,
2541+ f"expected a positive input, got { float (x )} " ):
2542+ math .log (x )
2543+ x = - 123
2544+ with self .assertRaisesRegex (ValueError ,
2545+ "expected a positive input$" ):
2546+ math .log (x )
2547+ with self .assertRaisesRegex (ValueError ,
2548+ f"expected a noninteger or positive integer, got { x } " ):
2549+ math .gamma (x )
2550+ x = 1.0
2551+ with self .assertRaisesRegex (ValueError ,
2552+ f"expected a number between -1 and 1, got { x } " ):
2553+ math .atanh (x )
2554+
24982555 # Custom assertions.
24992556
25002557 def assertIsNaN (self , value ):
@@ -2724,6 +2781,9 @@ def test_fma_infinities(self):
27242781 or (sys .platform == "android" and platform .machine () == "x86_64" )
27252782 or support .linked_to_musl (), # gh-131032
27262783 f"this platform doesn't implement IEE 754-2008 properly" )
2784+ # gh-131032: musl is fixed but the fix is not yet released; when the fixed
2785+ # version is known change this to:
2786+ # or support.linked_to_musl() < (1, <m>, <p>)
27272787 def test_fma_zero_result (self ):
27282788 nonnegative_finites = [0.0 , 1e-300 , 2.3 , 1e300 ]
27292789
0 commit comments