-
-
Notifications
You must be signed in to change notification settings - Fork 32k
testHypot in test_match uses assertEqual on floats #124040
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
Comments
cc @skirpichev as the author of c61de45 |
IIRC, this test error condition for PyLong_AsDouble/PyFloat_AsDouble (-1 is returned without exception set). I think that we could just drop 1st argument. I'll double check that & propose a patch. Edit: using assertAlmostEqual seems ok for me, but most tests in the testHypot() use carefully chosen arguments to compare computed values exactly. |
One-argument form is enough to test L2636 and compare computed values exactly.
One-argument form is enough to test L2636 and compare computed values exactly.
pr is ready for review: #124042 |
There's another similar tests that fails with the same error:
|
Ah, that's from 9c18b1a. I think we could just add two units: diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index c93876e701..dba017a9bb 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -969,9 +969,9 @@ def testDist(self):
self.assertEqual(dist((D(14), D(1)), (D(2), D(-4))), D(13))
self.assertEqual(dist((F(14, 32), F(1, 32)), (F(2, 32), F(-4, 32))),
F(13, 32))
- self.assertEqual(dist((True, True, False, True, False),
- (True, False, True, True, False)),
- sqrt(2.0))
+ self.assertEqual(dist((True, True, False, False, True, True),
+ (True, False, True, False, False, False)),
+ 2.0)
# Test corner cases
self.assertEqual(dist((13.25, 12.5, -3.25), |
I believe that the algorithm that @rhettinger implemented for Note that CPython these days does require that the C At a guess, the problem on i586 is that we don't have strict IEEE 754 semantics, because we're making use of the x87 floating-point instructions (with the 80-bit x87 floating-point format) and so ending up with double rounding on some arithmetic operations. The other possible cause here is that the code is using FMA/FMS instructions where it shouldn't be (or conversely, is not using FMA/FMS instructions where it's expected to). But my bet's on x87 arithmetic and double rounding. Possibly we should find a way to detect the x87/double-rounding situation and either skip or weaken the precise tests on machines that have that issue. There's precedent for this elsewhere in the Python test suite (e.g., in the tests for |
@mcepl, could you add decorator @unittest.skipIf(HAVE_DOUBLE_ROUNDING, "") on top of testHypot/testDist and test again? @mdickinson, thank you for reply.
E.g. testHypotAccuracy(). But tests in testHypot/testDist are more basic: sanity checks for arguments, etc. I don't think that filtering out these test functions is a good idea. BTW, Tim Peters told us, that you are resigned as a core developer (I hope, that my bad pr's weren't at least partially a reason). Yet you are listed in devguide in the expert index. Is it still ok to mention you in relevant topics? |
Ah, thanks for pointing that out. I've opened a PR to fix that: python/devguide#1397
Sure, mention away! I may not always have time to respond, though. |
I can confirm that this PR solves all the issues. |
…y computed results (pythonGH-124042) (cherry picked from commit 4420cf4) Co-authored-by: Sergey B Kirpichev <[email protected]>
…y computed results (pythonGH-124042) (cherry picked from commit 4420cf4) Co-authored-by: Sergey B Kirpichev <[email protected]>
…ly computed results (GH-124042) (GH-124236) (cherry picked from commit 4420cf4) Co-authored-by: Sergey B Kirpichev <[email protected]>
…y computed results (pythonGH-124042)
It seems, all merged. |
https://github.com/python/cpython/blob/main/Lib/test/test_math.py#L794-L871
We (SUSE) have test
self.assertEqual(hypot(1, -1), math.sqrt(2))
failing on some distros and some architectures (namelyi586
) and I suspect that whole idea ofassertEqual
on two floating point numbers is very unfortunate. Shouldn't be there at leastassertAlmostEqual
?Cc: @mdickinson, @rhettinger, @danigm
Linked PRs
The text was updated successfully, but these errors were encountered: