-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
AIX: self.assertEqualSign(math.nextafter(-0.0, +0.0), +0.0) test fails on AIX #83577
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
As bpo-39288 (that introduces this breakage) is closed, opening a new issue. Back from away - and only starting my investigation - and that will probably be slow. Have not done anything with IEEE754 in over 30 years. |
Please elaborate. What is the error? |
As I said, was investigating. a) is a bug in most AIX system libraries. c) the fix is APAR IV95512 which includes fixes in the following filesets: IV95512 shipped nextafter(+0.0, -0.0) returns +0.0 instead of -0.0. So, nothing for me "to fix" -- see https://www-01.ibm.com/support/docview.wss?uid=isg1IV95512 FYI: The document URL (above) was last modified on 30 October 2017 |
Ah, I saw an error on POWER6 AIX 3.x ("POWER6 (aka ppc64-be) using (GCC) 4.7.4"): The following test fails:
Well, C code specific to AIX can be added to nextafter() to handle this corner case: diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 81d871786f..82ffb4c3d1 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -3287,7 +3287,16 @@ static PyObject *
math_nextafter_impl(PyObject *module, double x, double y)
/*[clinic end generated code: output=750c8266c1c540ce input=02b2d50cd1d9f9b6]*/
{
- double f = nextafter(x, y);
+ double f;
+#if defined(_AIX)
+ if (x == y) {
+ f = y;
+ }
+ else
+#endif
+ {
+ f = nextafter(x, y);
+ }
return PyFloat_FromDouble(f);
}
Another option is to not make the assumption on the libc nextafter() and handle x==y the same way on all platforms. Error: ====================================================================== Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.aixtools-aix-power6/build/Lib/test/test_math.py", line 2040, in test_nextafter
self.assertEqualSign(math.nextafter(-0.0, +0.0), +0.0)
File "/home/buildbot/buildarea/3.x.aixtools-aix-power6/build/Lib/test/test_math.py", line 2018, in assertEqualSign
self.assertEqual(math.copysign(1.0, x), math.copysign(1.0, y))
AssertionError: -1.0 != 1.0 Same error in test_cmath: ====================================================================== Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.aixtools-aix-power6/build/Lib/test/test_math.py", line 2040, in test_nextafter
self.assertEqualSign(math.nextafter(-0.0, +0.0), +0.0)
File "/home/buildbot/buildarea/3.x.aixtools-aix-power6/build/Lib/test/test_math.py", line 2018, in assertEqualSign
self.assertEqual(math.copysign(1.0, x), math.copysign(1.0, y))
AssertionError: -1.0 != 1.0 |
A hard call to make, imho. Thinking aloud... Currently, for AIX 6.1 and AIX 7.1 your proposal for the code change would be great, but less so for AIX 7.2. However! Since libm (on AIX) is a static library - the behavior depends on the support libm has on the build system. I'll have to puzzle a bit with the configure process and figure out how to best determine the behavior of the build system. On a properly patched AIX 7.2 system the standard code would apply, on others the "adjusted behavior". So, would you go for modified based on what version of libm is installed, better how this function is behaving? |
Checking how Python is linked or checking the libm version sounds overkill to me. "if (x == y)" test is really cheap: I don't expect nextafter() to be used in performance critical code path anyway. That's why I even consider to add this code path on all platforms, not only AIX. Mark: what's your call on that one? Make the code conditional on AIX? In practice, it seems like only (old libm) AIX nextafter() requires to be "patched". |
FYI: On AIX 5.3, after your proposal I get: ====================================================================== Traceback (most recent call last):
File "/data/prj/python/git/python3-3.9/Lib/test/test_cmath.py", line 418, in test_specific_values
self.rAssertAlmostEqual(expected.imag, actual.imag,
File "/data/prj/python/git/python3-3.9/Lib/test/test_cmath.py", line 130, in rAssertAlmostEqual
self.fail(msg or 'zero has wrong sign: expected {!r}, '
AssertionError: exp0001: exp(complex(0.0, -0.0))
Expected: complex(1.0, -0.0)
Received: complex(1.0, 0.0)
Received value insufficiently close to expected value. So, test_nextafter works with the patch, but test_specific_values remains 'active' |
I don't know. It's a hard problem in general: where do we draw the line between simply wrapping the platform libm, bugs and all, on one hand and trying to abstract away platform differences and make guarantees about corner-case behaviour on the other. For this particular case, I'd be fine with adding a special case for Actually, the cmath.exp failure looks a little odd to my eyes: it would be a bit surprising to have cmath.exp fail if all of test_math passed. I suspect a dodgy compiler optimisation. But that's another issue. |
BTW, stupid question: why is |
I proposed PR 18094. Because of your parenthesis, I chose to use "#if defined(_AIX)" with an an explicit comment on AIX version. For example, we may drop this workaround once we would like to drop support for AIX 7.1.
Michael: would you mind to open a separated issue for "FAIL: test_specific_values (test.test_cmath.CMathTests)"? Is it on a buildbot? Please try to get the machine code of cmath_exp_impl() function. Example: objdump -d build/lib.linux-x86_64-3.9-pydebug/cmath.cpython-39d-x86_64-linux-gnu.so or try gdb: $ gdb ./python
GNU gdb (GDB) Fedora 8.3.50.20190824-26.fc31
(gdb) run
>>> import cmath <press CTRL+C> Program received signal SIGINT, Interrupt. |
So on cmath.exp, we've seen something like this before, on macOS. What was happening was that the C source contained matching I don't have an issue reference to hand; all this is from (highly fallible) memory. |
See bpo-18513. |
My change should fix nextafter test failure on AIX. Again, please open a separated issue for "FAIL: test_specific_values (test.test_cmath.CMathTests)". |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: