Skip to content

Commit

Permalink
[3.13] gh-123836: Check zero signs in math_testcases.txt (GH-123854) (#…
Browse files Browse the repository at this point in the history
…124161)

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 28aea5d)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
  • Loading branch information
miss-islington and skirpichev committed Sep 30, 2024
1 parent 99185bd commit 5e27117
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2053,6 +2056,13 @@ def test_testfile(self):
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

Expand Down

0 comments on commit 5e27117

Please sign in to comment.