Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing math_testcases.txt lacks support for signed zeros #123836

Closed
skirpichev opened this issue Sep 8, 2024 · 5 comments
Closed

Testing math_testcases.txt lacks support for signed zeros #123836

skirpichev opened this issue Sep 8, 2024 · 5 comments
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@skirpichev
Copy link
Member

skirpichev commented Sep 8, 2024

Feature or enhancement

Proposal:

This file tested, using result_check() helper:

def result_check(expected, got, ulp_tol=5, abs_tol=0.0):

which lacks checking of zero sign (while some entries in the data file - have signed zeros). C.f. cmath_testcases.txt, which tested with rAssertAlmostEqual(), that has such special case:
# if both a and b are zero, check whether they have the same sign
# (in theory there are examples where it would be legitimate for a
# and b to have opposite signs; in practice these hardly ever
# occur).
if not a and not b:
if math.copysign(1., a) != math.copysign(1., b):
self.fail(msg or 'zero has wrong sign: expected {!r}, '
'got {!r}'.format(a, b))

I think that first helper should be adjusted to do same. I'll work on a patch.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

@skirpichev skirpichev added the type-feature A feature request or enhancement label Sep 8, 2024
@picnixz picnixz added the tests Tests in the Lib/test dir label Sep 8, 2024
skirpichev added a commit to skirpichev/cpython that referenced this issue Sep 9, 2024
Just like cmath_testcases.txt.  These tests require IEEE 754 anyway.
@skirpichev
Copy link
Member Author

PR is ready for review: #123854

vstinner pushed a commit that referenced this issue Sep 17, 2024
Just like cmath_testcases.txt. These tests require IEEE 754 anyway.

Correct zero sign for sqrt tests to match math.h convention.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 17, 2024
)

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]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 17, 2024
)

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]>
@vstinner
Copy link
Member

Implemented as 28aea5d. Backports will follow.

vstinner pushed a commit that referenced this issue Sep 17, 2024
…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]>
@encukou
Copy link
Member

encukou commented Sep 17, 2024

This broke the Windows 10 buildbot: #123854 (comment)

@encukou encukou reopened this Sep 17, 2024
skirpichev added a commit to skirpichev/cpython that referenced this issue Sep 17, 2024
Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

This amends 28aea5d.
skirpichev added a commit to skirpichev/cpython that referenced this issue Sep 17, 2024
Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

Here Windows loose sign of the result; if y is nonzero, the result
should have the same sign as x.

This amends 28aea5d.
@skirpichev
Copy link
Member Author

Fix: #124171

vstinner pushed a commit that referenced this issue Sep 17, 2024
Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

Here Windows loose sign of the result; if y is nonzero, the result
should have the same sign as x.

This amends commit 28aea5d.
skirpichev added a commit to skirpichev/cpython that referenced this issue Sep 17, 2024
…H-124171)

Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

Here Windows loose sign of the result; if y is nonzero, the result
should have the same sign as x.

This amends commit 28aea5d.
(cherry picked from commit f4dd440)

Co-authored-by: Sergey B Kirpichev <[email protected]>
vstinner pushed a commit that referenced this issue Sep 17, 2024
…124186)

Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

Here Windows loose sign of the result; if y is nonzero, the result
should have the same sign as x.

This amends commit 28aea5d.
(cherry picked from commit f4dd440)
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this issue Sep 22, 2024
Just like cmath_testcases.txt. These tests require IEEE 754 anyway.

Correct zero sign for sqrt tests to match math.h convention.
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this issue Sep 22, 2024
Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

Here Windows loose sign of the result; if y is nonzero, the result
should have the same sign as x.

This amends commit 28aea5d.
Yhg1s pushed a commit that referenced this issue Sep 30, 2024
…124187)

Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

Here Windows loose sign of the result; if y is nonzero, the result
should have the same sign as x.

This amends commit 28aea5d.
(cherry picked from commit f4dd440)
Yhg1s pushed a commit that referenced this issue Sep 30, 2024
…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 <[email protected]>
@vstinner
Copy link
Member

Congrats @skirpichev for this nice enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants