Skip to content

Commit 5e27117

Browse files
[3.13] pythongh-123836: Check zero signs in math_testcases.txt (pythonGH-123854) (python#124161)
pythongh-123836: Check zero signs in math_testcases.txt (pythonGH-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>
1 parent 99185bd commit 5e27117

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"
@@ -2053,6 +2056,13 @@ def test_testfile(self):
20532056
except OverflowError:
20542057
result = 'OverflowError'
20552058

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

0 commit comments

Comments
 (0)