]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123836: Check zero signs in math_testcases.txt (#123854)
authorSergey B Kirpichev <skirpichev@gmail.com>
Tue, 17 Sep 2024 08:22:40 +0000 (11:22 +0300)
committerGitHub <noreply@github.com>
Tue, 17 Sep 2024 08:22:40 +0000 (10:22 +0200)
Just like cmath_testcases.txt. These tests require IEEE 754 anyway.

Correct zero sign for sqrt tests to match math.h convention.

Lib/test/test_math.py

index eabab2805f811013626c4b8ef255cac9c4f1ae86..cf452960729aba83c6a2bfb67d065b955b8ed814 100644 (file)
@@ -187,6 +187,9 @@ def result_check(expected, got, ulp_tol=5, abs_tol=0.0):
 
     # Check exactly equal (applies also to strings representing exceptions)
     if got == expected:
+        if not got and not expected:
+            if math.copysign(1, got) != math.copysign(1, expected):
+                return f"expected {expected}, got {got} (zero has wrong sign)"
         return None
 
     failure = "not equal"
@@ -2067,6 +2070,13 @@ class MathTests(unittest.TestCase):
             except OverflowError:
                 result = 'OverflowError'
 
+            # C99+ says for math.h's sqrt: If the argument is +∞ or ±0, it is
+            # returned, unmodified.  On another hand, for csqrt: If z is ±0+0i,
+            # the result is +0+0i.  Lets correct zero sign of er to follow
+            # first convention.
+            if id in ['sqrt0002', 'sqrt0003', 'sqrt1001', 'sqrt1023']:
+                er = math.copysign(er, ar)
+
             # Default tolerances
             ulp_tol, abs_tol = 5, 0.0