@@ -2637,9 +2637,10 @@ def test_fma_nan_results(self):
2637
2637
2638
2638
# If any input is a NaN, the result should be a NaN, too.
2639
2639
for a , b in itertools .product (values , repeat = 2 ):
2640
- self .assertIsNaN (math .fma (math .nan , a , b ))
2641
- self .assertIsNaN (math .fma (a , math .nan , b ))
2642
- self .assertIsNaN (math .fma (a , b , math .nan ))
2640
+ with self .subTest (a = a , b = b ):
2641
+ self .assertIsNaN (math .fma (math .nan , a , b ))
2642
+ self .assertIsNaN (math .fma (a , math .nan , b ))
2643
+ self .assertIsNaN (math .fma (a , b , math .nan ))
2643
2644
2644
2645
def test_fma_infinities (self ):
2645
2646
# Cases involving infinite inputs or results.
@@ -2651,57 +2652,62 @@ def test_fma_infinities(self):
2651
2652
for c in non_nans :
2652
2653
for infinity in [math .inf , - math .inf ]:
2653
2654
for zero in [0.0 , - 0.0 ]:
2654
- with self .assertRaises (ValueError ):
2655
- math .fma (infinity , zero , c )
2656
- with self .assertRaises (ValueError ):
2657
- math .fma (zero , infinity , c )
2655
+ with self .subTest (c = c , infinity = infinity , zero = zero ):
2656
+ with self .assertRaises (ValueError ):
2657
+ math .fma (infinity , zero , c )
2658
+ with self .assertRaises (ValueError ):
2659
+ math .fma (zero , infinity , c )
2658
2660
2659
2661
# ValueError when a*b and c both infinite of opposite signs.
2660
2662
for b in positives :
2661
- with self .assertRaises (ValueError ):
2662
- math .fma (math .inf , b , - math .inf )
2663
- with self .assertRaises (ValueError ):
2664
- math .fma (math .inf , - b , math .inf )
2665
- with self .assertRaises (ValueError ):
2666
- math .fma (- math .inf , - b , - math .inf )
2667
- with self .assertRaises (ValueError ):
2668
- math .fma (- math .inf , b , math .inf )
2669
- with self .assertRaises (ValueError ):
2670
- math .fma (b , math .inf , - math .inf )
2671
- with self .assertRaises (ValueError ):
2672
- math .fma (- b , math .inf , math .inf )
2673
- with self .assertRaises (ValueError ):
2674
- math .fma (- b , - math .inf , - math .inf )
2675
- with self .assertRaises (ValueError ):
2676
- math .fma (b , - math .inf , math .inf )
2663
+ with self .subTest (b = b ):
2664
+ with self .assertRaises (ValueError ):
2665
+ math .fma (math .inf , b , - math .inf )
2666
+ with self .assertRaises (ValueError ):
2667
+ math .fma (math .inf , - b , math .inf )
2668
+ with self .assertRaises (ValueError ):
2669
+ math .fma (- math .inf , - b , - math .inf )
2670
+ with self .assertRaises (ValueError ):
2671
+ math .fma (- math .inf , b , math .inf )
2672
+ with self .assertRaises (ValueError ):
2673
+ math .fma (b , math .inf , - math .inf )
2674
+ with self .assertRaises (ValueError ):
2675
+ math .fma (- b , math .inf , math .inf )
2676
+ with self .assertRaises (ValueError ):
2677
+ math .fma (- b , - math .inf , - math .inf )
2678
+ with self .assertRaises (ValueError ):
2679
+ math .fma (b , - math .inf , math .inf )
2677
2680
2678
2681
# Infinite result when a*b and c both infinite of the same sign.
2679
2682
for b in positives :
2680
- self .assertEqual (math .fma (math .inf , b , math .inf ), math .inf )
2681
- self .assertEqual (math .fma (math .inf , - b , - math .inf ), - math .inf )
2682
- self .assertEqual (math .fma (- math .inf , - b , math .inf ), math .inf )
2683
- self .assertEqual (math .fma (- math .inf , b , - math .inf ), - math .inf )
2684
- self .assertEqual (math .fma (b , math .inf , math .inf ), math .inf )
2685
- self .assertEqual (math .fma (- b , math .inf , - math .inf ), - math .inf )
2686
- self .assertEqual (math .fma (- b , - math .inf , math .inf ), math .inf )
2687
- self .assertEqual (math .fma (b , - math .inf , - math .inf ), - math .inf )
2683
+ with self .subTest (b = b ):
2684
+ self .assertEqual (math .fma (math .inf , b , math .inf ), math .inf )
2685
+ self .assertEqual (math .fma (math .inf , - b , - math .inf ), - math .inf )
2686
+ self .assertEqual (math .fma (- math .inf , - b , math .inf ), math .inf )
2687
+ self .assertEqual (math .fma (- math .inf , b , - math .inf ), - math .inf )
2688
+ self .assertEqual (math .fma (b , math .inf , math .inf ), math .inf )
2689
+ self .assertEqual (math .fma (- b , math .inf , - math .inf ), - math .inf )
2690
+ self .assertEqual (math .fma (- b , - math .inf , math .inf ), math .inf )
2691
+ self .assertEqual (math .fma (b , - math .inf , - math .inf ), - math .inf )
2688
2692
2689
2693
# Infinite result when a*b finite, c infinite.
2690
2694
for a , b in itertools .product (finites , finites ):
2691
- self .assertEqual (math .fma (a , b , math .inf ), math .inf )
2692
- self .assertEqual (math .fma (a , b , - math .inf ), - math .inf )
2695
+ with self .subTest (b = b ):
2696
+ self .assertEqual (math .fma (a , b , math .inf ), math .inf )
2697
+ self .assertEqual (math .fma (a , b , - math .inf ), - math .inf )
2693
2698
2694
2699
# Infinite result when a*b infinite, c finite.
2695
2700
for b , c in itertools .product (positives , finites ):
2696
- self .assertEqual (math .fma (math .inf , b , c ), math .inf )
2697
- self .assertEqual (math .fma (- math .inf , b , c ), - math .inf )
2698
- self .assertEqual (math .fma (- math .inf , - b , c ), math .inf )
2699
- self .assertEqual (math .fma (math .inf , - b , c ), - math .inf )
2701
+ with self .subTest (b = b , c = c ):
2702
+ self .assertEqual (math .fma (math .inf , b , c ), math .inf )
2703
+ self .assertEqual (math .fma (- math .inf , b , c ), - math .inf )
2704
+ self .assertEqual (math .fma (- math .inf , - b , c ), math .inf )
2705
+ self .assertEqual (math .fma (math .inf , - b , c ), - math .inf )
2700
2706
2701
- self .assertEqual (math .fma (b , math .inf , c ), math .inf )
2702
- self .assertEqual (math .fma (b , - math .inf , c ), - math .inf )
2703
- self .assertEqual (math .fma (- b , - math .inf , c ), math .inf )
2704
- self .assertEqual (math .fma (- b , math .inf , c ), - math .inf )
2707
+ self .assertEqual (math .fma (b , math .inf , c ), math .inf )
2708
+ self .assertEqual (math .fma (b , - math .inf , c ), - math .inf )
2709
+ self .assertEqual (math .fma (- b , - math .inf , c ), math .inf )
2710
+ self .assertEqual (math .fma (- b , math .inf , c ), - math .inf )
2705
2711
2706
2712
# gh-73468: On some platforms, libc fma() doesn't implement IEE 754-2008
2707
2713
# properly: it doesn't use the right sign when the result is zero.
@@ -2714,23 +2720,24 @@ def test_fma_zero_result(self):
2714
2720
2715
2721
# Zero results from exact zero inputs.
2716
2722
for b in nonnegative_finites :
2717
- self .assertIsPositiveZero (math .fma (0.0 , b , 0.0 ))
2718
- self .assertIsPositiveZero (math .fma (0.0 , b , - 0.0 ))
2719
- self .assertIsNegativeZero (math .fma (0.0 , - b , - 0.0 ))
2720
- self .assertIsPositiveZero (math .fma (0.0 , - b , 0.0 ))
2721
- self .assertIsPositiveZero (math .fma (- 0.0 , - b , 0.0 ))
2722
- self .assertIsPositiveZero (math .fma (- 0.0 , - b , - 0.0 ))
2723
- self .assertIsNegativeZero (math .fma (- 0.0 , b , - 0.0 ))
2724
- self .assertIsPositiveZero (math .fma (- 0.0 , b , 0.0 ))
2725
-
2726
- self .assertIsPositiveZero (math .fma (b , 0.0 , 0.0 ))
2727
- self .assertIsPositiveZero (math .fma (b , 0.0 , - 0.0 ))
2728
- self .assertIsNegativeZero (math .fma (- b , 0.0 , - 0.0 ))
2729
- self .assertIsPositiveZero (math .fma (- b , 0.0 , 0.0 ))
2730
- self .assertIsPositiveZero (math .fma (- b , - 0.0 , 0.0 ))
2731
- self .assertIsPositiveZero (math .fma (- b , - 0.0 , - 0.0 ))
2732
- self .assertIsNegativeZero (math .fma (b , - 0.0 , - 0.0 ))
2733
- self .assertIsPositiveZero (math .fma (b , - 0.0 , 0.0 ))
2723
+ with self .subTest (b = b ):
2724
+ self .assertIsPositiveZero (math .fma (0.0 , b , 0.0 ))
2725
+ self .assertIsPositiveZero (math .fma (0.0 , b , - 0.0 ))
2726
+ self .assertIsNegativeZero (math .fma (0.0 , - b , - 0.0 ))
2727
+ self .assertIsPositiveZero (math .fma (0.0 , - b , 0.0 ))
2728
+ self .assertIsPositiveZero (math .fma (- 0.0 , - b , 0.0 ))
2729
+ self .assertIsPositiveZero (math .fma (- 0.0 , - b , - 0.0 ))
2730
+ self .assertIsNegativeZero (math .fma (- 0.0 , b , - 0.0 ))
2731
+ self .assertIsPositiveZero (math .fma (- 0.0 , b , 0.0 ))
2732
+
2733
+ self .assertIsPositiveZero (math .fma (b , 0.0 , 0.0 ))
2734
+ self .assertIsPositiveZero (math .fma (b , 0.0 , - 0.0 ))
2735
+ self .assertIsNegativeZero (math .fma (- b , 0.0 , - 0.0 ))
2736
+ self .assertIsPositiveZero (math .fma (- b , 0.0 , 0.0 ))
2737
+ self .assertIsPositiveZero (math .fma (- b , - 0.0 , 0.0 ))
2738
+ self .assertIsPositiveZero (math .fma (- b , - 0.0 , - 0.0 ))
2739
+ self .assertIsNegativeZero (math .fma (b , - 0.0 , - 0.0 ))
2740
+ self .assertIsPositiveZero (math .fma (b , - 0.0 , 0.0 ))
2734
2741
2735
2742
# Exact zero result from nonzero inputs.
2736
2743
self .assertIsPositiveZero (math .fma (2.0 , 2.0 , - 4.0 ))
@@ -2836,12 +2843,14 @@ def test_random(self):
2836
2843
'0x1.f5467b1911fd6p-2' , '0x1.b5cee3225caa5p-1' ),
2837
2844
]
2838
2845
for a_hex , b_hex , c_hex , expected_hex in test_values :
2839
- a = float .fromhex (a_hex )
2840
- b = float .fromhex (b_hex )
2841
- c = float .fromhex (c_hex )
2842
- expected = float .fromhex (expected_hex )
2843
- self .assertEqual (math .fma (a , b , c ), expected )
2844
- self .assertEqual (math .fma (b , a , c ), expected )
2846
+ with self .subTest (a_hex = a_hex , b_hex = b_hex , c_hex = c_hex ,
2847
+ expected_hex = expected_hex ):
2848
+ a = float .fromhex (a_hex )
2849
+ b = float .fromhex (b_hex )
2850
+ c = float .fromhex (c_hex )
2851
+ expected = float .fromhex (expected_hex )
2852
+ self .assertEqual (math .fma (a , b , c ), expected )
2853
+ self .assertEqual (math .fma (b , a , c ), expected )
2845
2854
2846
2855
# Custom assertions.
2847
2856
def assertIsNaN (self , value ):
0 commit comments