8000 gh-123836: Check zero signs in math_testcases.txt (#123854) · python/cpython@28aea5d · GitHub
[go: up one dir, main page]

Skip to content

Commit 28aea5d

Browse files
authored
gh-123836: Check zero signs in math_testcases.txt (#123854)
Just like cmath_testcases.txt. These tests require IEEE 754 anyway. Correct zero sign for sqrt tests to match math.h convention.
1 parent 14e5bdc commit 28aea5d

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"
@@ -2067,6 +2070,13 @@ def test_testfile(self):
20672070
except OverflowError:
20682071
result = 'OverflowError'
20692072

2073+
# C99+ says for math.h's sqrt: If the argument is +∞ or ±0, it is
2074+
# returned, unmodified. On another hand, for csqrt: If z is ±0+0i,
2075+
# the result is +0+0i. Lets correct zero sign of er to follow
2076+
# first convention.
2077+
if id in ['sqrt0002', 'sqrt0003', 'sqrt1001', 'sqrt1023']:
2078+
er = math.copysign(er, ar)
2079+
20702080
# Default tolerances
20712081
ulp_tol, abs_tol = 5, 0.0
20722082

0 commit comments

Comments
 (0)
0