@@ -2693,9 +2693,10 @@ def test_fma_nan_results(self):
2693
2693
2694
2694
# If any input is a NaN, the result should be a NaN, too.
2695
2695
for a , b in itertools .product (values , repeat = 2 ):
2696
- self .assertIsNaN (math .fma (math .nan , a , b ))
2697
- self .assertIsNaN (math .fma (a , math .nan , b ))
2698
- self .assertIsNaN (math .fma (a , b , math .nan ))
2696
+ with self .subTest (a = a , b = b ):
2697
+ self .assertIsNaN (math .fma (math .nan , a , b ))
2698
+ self .assertIsNaN (math .fma (a , math .nan , b ))
2699
+ self .assertIsNaN (math .fma (a , b , math .nan ))
2699
2700
2700
2701
def test_fma_infinities (self ):
2701
2702
# Cases involving infinite inputs or results.
@@ -2707,57 +2708,62 @@ def test_fma_infinities(self):
2707
2708
for c in non_nans :
2708
2709
for infinity in [math .inf , - math .inf ]:
2709
2710
for zero in [0.0 , - 0.0 ]:
2710
- with self .assertRaises (ValueError ):
2711
- math .fma (infinity , zero , c )
2712
- with self .assertRaises (ValueError ):
2713
- math .fma (zero , infinity , c )
2711
+ with self .subTest (c = c , infinity = infinity , zero = zero ):
2712
+ with self .assertRaises (ValueError ):
2713
+ math .fma (infinity , zero , c )
2714
+ with self .assertRaises (ValueError ):
2715
+ math .fma (zero , infinity , c )
2714
2716
2715
2717
# ValueError when a*b and c both infinite of opposite signs.
2716
2718
for b in positives :
2717
- with self .assertRaises (ValueError ):
2718
- math .fma (math .inf , b , - math .inf )
2719
- with self .assertRaises (ValueError ):
2720
- math .fma (math .inf , - b , math .inf )
2721
- with self .assertRaises (ValueError ):
2722
- math .fma (- math .inf , - b , - math .inf )
2723
- with self .assertRaises (ValueError ):
2724
- math .fma (- math .inf , b , math .inf )
2725
- with self .assertRaises (ValueError ):
2726
- math .fma (b , math .inf , - math .inf )
2727
- with self .assertRaises (ValueError ):
2728
- math .fma (- b , math .inf , math .inf )
2729
- with self .assertRaises (ValueError ):
2730
- math .fma (- b , - math .inf , - math .inf )
2731
- with self .assertRaises (ValueError ):
2732
- math .fma (b , - math .inf , math .inf )
2719
+ with self .subTest (b = b ):
2720
+ with self .assertRaises (ValueError ):
2721
+ math .fma (math .inf , b , - math .inf )
2722
+ with self .assertRaises (ValueError ):
2723
+ math .fma (math .inf , - b , math .inf )
2724
+ with self .assertRaises (ValueError ):
2725
+ math .fma (- math .inf , - b , - math .inf )
2726
+ with self .assertRaises (ValueError ):
2727
+ math .fma (- math .inf , b , math .inf )
2728
+ with self .assertRaises (ValueError ):
2729
+ math .fma (b , math .inf , - math .inf )
2730
+ with self .assertRaises (ValueError ):
2731
+ math .fma (- b , math .inf , math .inf )
2732
+ with self .assertRaises (ValueError ):
2733
+ math .fma (- b , - math .inf , - math .inf )
2734
+ with self .assertRaises (ValueError ):
2735
+ math .fma (b , - math .inf , math .inf )
2733
2736
2734
2737
# Infinite result when a*b and c both infinite of the same sign.
2735
2738
for b in positives :
2736
- self .assertEqual (math .fma (math .inf , b , math .inf ), math .inf )
2737
- self .assertEqual (math .fma (math .inf , - b , - math .inf ), - math .inf )
2738
- self .assertEqual (math .fma (- math .inf , - b , math .inf ), math .inf )
2739
- self .assertEqual (math .fma (- math .inf , b , - math .inf ), - math .inf )
2740
- self .assertEqual (math .fma (b , math .inf , math .inf ), math .inf )
2741
- self .assertEqual (math .fma (- b , math .inf , - math .inf ), - math .inf )
2742
- self .assertEqual (math .fma (- b , - math .inf , math .inf ), math .inf )
2743
- self .assertEqual (math .fma (b , - math .inf , - math .inf ), - math .inf )
2739
+ with self .subTest (b = b ):
2740
+ self .assertEqual (math .fma (math .inf , b , math .inf ), math .inf )
2741
+ self .assertEqual (math .fma (math .inf , - b , - math .inf ), - math .inf )
2742
+ self .assertEqual (math .fma (- math .inf , - b , math .inf ), math .inf )
2743
+ self .assertEqual (math .fma (- math .inf , b , - math .inf ), - math .inf )
2744
+ self .assertEqual (math .fma (b , math .inf , math .inf ), math .inf )
2745
+ self .assertEqual (math .fma (- b , math .inf , - math .inf ), - math .inf )
2746
+ self .assertEqual (math .fma (- b , - math .inf , math .inf ), math .inf )
2747
+ self .assertEqual (math .fma (b , - math .inf , - math .inf ), - math .inf )
2744
2748
2745
2749
# Infinite result when a*b finite, c infinite.
2746
2750
for a , b in itertools .product (finites , finites ):
2747
- self .assertEqual (math .fma (a , b , math .inf ), math .inf )
2748
- self .assertEqual (math .fma (a , b , - math .inf ), - math .inf )
2751
+ with self .subTest (b = b ):
2752
+ self .assertEqual (math .fma (a , b , math .inf ), math .inf )
2753
+ self .assertEqual (math .fma (a , b , - math .inf ), - math .inf )
2749
2754
2750
2755
# Infinite result when a*b infinite, c finite.
2751
2756
for b , c in itertools .product (positives , finites ):
2752
- self .assertEqual (math .fma (math .inf , b , c ), math .inf )
2753
- self .assertEqual (math .fma (- math .inf , b , c ), - math .inf )
2754
- self .assertEqual (math .fma (- math .inf , - b , c ), math .inf )
2755
- self .assertEqual (math .fma (math .inf , - b , c ), - math .inf )
2757
+ with self .subTest (b = b , c = c ):
2758
+ self .assertEqual (math .fma (math .inf , b , c ), math .inf )
2759
+ self .assertEqual (math .fma (- math .inf , b , c ), - math .inf )
2760
+ self .assertEqual (math .fma (- math .inf , - b , c ), math .inf )
2761
+ self .assertEqual (math .fma (math .inf , - b , c ), - math .inf )
2756
2762
2757
- self .assertEqual (math .fma (b , math .inf , c ), math .inf )
2758
- self .assertEqual (math .fma (b , - math .inf , c ), - math .inf )
2759
- self .assertEqual (math .fma (- b , - math .inf , c ), math .inf )
2760
- self .assertEqual (math .fma (- b , math .inf , c ), - math .inf )
2763
+ self .assertEqual (math .fma (b , math .inf , c ), math .inf )
2764
+ self .assertEqual (math .fma (b , - math .inf , c ), - math .inf )
2765
+ self .assertEqual (math .fma (- b , - math .inf , c ), math .inf )
2766
+ self .assertEqual (math .fma (- b , math .inf , c ), - math .inf )
2761
2767
2762
2768
# gh-73468: On some platforms, libc fma() doesn't implement IEE 754-2008
2763
2769
# properly: it doesn't use the right sign when the result is zero.
@@ -2770,23 +2776,24 @@ def test_fma_zero_result(self):
2770
2776
2771
2777
# Zero results from exact zero inputs.
2772
2778
for b in nonnegative_finites :
2773
- self .assertIsPositiveZero (math .fma (0.0 , b , 0.0 ))
2774
- self .assertIsPositiveZero (math .fma (0.0 , b , - 0.0 ))
2775
- self .assertIsNegativeZero (math .fma (0.0 , - b , - 0.0 ))
2776
- self .assertIsPositiveZero (math .fma (0.0 , - b , 0.0 ))
2777
- self .assertIsPositiveZero (math .fma (- 0.0 , - b , 0.0 ))
2778
- self .assertIsPositiveZero (math .fma (- 0.0 , - b , - 0.0 ))
2779
- self .assertIsNegativeZero (math .fma (- 0.0 , b , - 0.0 ))
2780
- self .assertIsPositiveZero (math .fma (- 0.0 , b , 0.0 ))
2781
-
2782
- self .assertIsPositiveZero (math .fma (b , 0.0 , 0.0 ))
2783
- self .assertIsPositiveZero (math .fma (b , 0.0 , - 0.0 ))
2784
- self .assertIsNegativeZero (math .fma (- b , 0.0 , - 0.0 ))
2785
- self .assertIsPositiveZero (math .fma (- b , 0.0 , 0.0 ))
2786
- self .assertIsPositiveZero (math .fma (- b , - 0.0 , 0.0 ))
2787
- self .assertIsPositiveZero (math .fma (- b , - 0.0 , - 0.0 ))
2788
- self .assertIsNegativeZero (math .fma (b , - 0.0 , - 0.0 ))
2789
- self .assertIsPositiveZero (math .fma (b , - 0.0 , 0.0 ))
2779
+ with self .subTest (b = b ):
2780
+ self .assertIsPositiveZero (math .fma (0.0 , b , 0.0 ))
2781
+ self .assertIsPositiveZero (math .fma (0.0 , b , - 0.0 ))
2782
+ self .assertIsNegativeZero (math .fma (0.0 , - b , - 0.0 ))
2783
+ self .assertIsPositiveZero (math .fma (0.0 , - b , 0.0 ))
2784
+ self .assertIsPositiveZero (math .fma (- 0.0 , - b , 0.0 ))
2785
+ self .assertIsPositiveZero (math .fma (- 0.0 , - b , - 0.0 ))
2786
+ self .assertIsNegativeZero (math .fma (- 0.0 , b , - 0.0 ))
2787
+ self .assertIsPositiveZero (math .fma (- 0.0 , b , 0.0 ))
2788
+
2789
+ self .assertIsPositiveZero (math .fma (b , 0.0 , 0.0 ))
2790
+ self .assertIsPositiveZero (math .fma (b , 0.0 , - 0.0 ))
2791
+ self .assertIsNegativeZero (math .fma (- b , 0.0 , - 0.0 ))
2792
+ self .assertIsPositiveZero (math .fma (- b , 0.0 , 0.0 ))
2793
+ self .assertIsPositiveZero (math .fma (- b , - 0.0 , 0.0 ))
2794
+ self .assertIsPositiveZero (math .fma (- b , - 0.0 , - 0.0 ))
2795
+ self .assertIsNegativeZero (math .fma (b , - 0.0 , - 0.0 ))
2796
+ self .assertIsPositiveZero (math .fma (b , - 0.0 , 0.0 ))
2790
2797
2791
2798
# Exact zero result from nonzero inputs.
2792
2799
self .assertIsPositiveZero (math .fma (2.0 , 2.0 , - 4.0 ))
@@ -2892,12 +2899,14 @@ def test_random(self):
2892
2899
'0x1.f5467b1911fd6p-2' , '0x1.b5cee3225caa5p-1' ),
2893
2900
]
2894
2901
for a_hex , b_hex , c_hex , expected_hex in test_values :
2895
- a = float .fromhex (a_hex )
2896
- b = float .fromhex (b_hex )
2897
- c = float .fromhex (c_hex )
2898
- expected = float .fromhex (expected_hex )
2899
- self .assertEqual (math .fma (a , b , c ), expected )
2900
- self .assertEqual (math .fma (b , a , c ), expected )
2902
+ with self .subTest (a_hex = a_hex , b_hex = b_hex , c_hex = c_hex ,
2903
+ expected_hex = expected_hex ):
2904
+ a = float .fromhex (a_hex )
2905
+ b = float .fromhex (b_hex )
2906
+ c = float .fromhex (c_hex )
2907
+ expected = float .fromhex (expected_hex )
2908
+ self .assertEqual (math .fma (a , b , c ), expected )
2909
+ self .assertEqual (math .fma (b , a , c ), expected )
2901
2910
2902
2911
# Custom assertions.
2903
2912
def assertIsNaN (self , value ):
0 commit comments