]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-123836: Check zero signs in math_testcases.txt (GH-123854) (#124161)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 30 Sep 2024 01:14:44 +0000 (03:14 +0200)
committerGitHub <noreply@github.com>
Mon, 30 Sep 2024 01:14:44 +0000 (18:14 -0700)
gh-123836: Check zero signs in math_testcases.txt (GH-123854)

Just like cmath_testcases.txt. These tests require IEEE 754 anyway.

Correct zero sign for sqrt tests to match math.h convention.
(cherry picked from commit 28aea5d07d163105b42acd81c1651397ef95ea57)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Lib/test/test_math.py

index f50b2ebb6fd6d0a631328c332223a84c7b3fedec..541ccdb3d09ccd1de5a2d4e1d228a703681efa56 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"
@@ -2053,6 +2056,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