Skip to content

Commit c54ee87

Browse files
[3.12] gh-123836: Check zero signs in math_testcases.txt (GH-123854) (#124162)
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 <[email protected]>
1 parent 92bc714 commit c54ee87

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Lib/test/test_math.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ def result_check(expected, got, ulp_tol=5, abs_tol=0.0):
187187

188188
# Check exactly equal (applies also to strings representing exceptions)
189189
if got == expected:
190+
if not got and not expected:
191+
if math.copysign(1, got) != math.copysign(1, expected):
192+
return f"expected {expected}, got {got} (zero has wrong sign)"
190193
return None
191194

192195
failure = "not equal"
@@ -2051,6 +2054,13 @@ def test_testfile(self):
20512054
except OverflowError:
20522055
result = 'OverflowError'
20532056

2057+
# C99+ says for math.h's sqrt: If the argument is +∞ or ±0, it is
2058+
# returned, unmodified. On another hand, for csqrt: If z is ±0+0i,
2059+
# the result is +0+0i. Lets correct zero sign of er to follow
2060+
# first convention.
2061+
if id in ['sqrt0002', 'sqrt0003', 'sqrt1001', 'sqrt1023']:
2062+
er = math.copysign(er, ar)
2063+
20542064
# Default tolerances
20552065
ulp_tol, abs_tol = 5, 0.0
20562066

0 commit comments

Comments
 (0)