Repository navigation
test_math.test_fma_zero_result() fails with the musl C library #131032
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 10, 2025 Can you try to re-run test_math in verbose mode? Something like:
./python -m test test_math -vin the directory where you built Python.the following is the result for the verbose mode.
/Python-3.13.2 # ./python -m unittest -v test.test_math test_fma_infinities (test.test_math.FMATests.test_fma_infinities) ... ok test_fma_nan_results (test.test_math.FMATests.test_fma_nan_results) ... ok test_fma_overflow (test.test_math.FMATests.test_fma_overflow) ... ok test_fma_single_round (test.test_math.FMATests.test_fma_single_round) ... ok test_fma_zero_result (test.test_math.FMATests.test_fma_zero_result) ... FAIL test_random (test.test_math.FMATests.test_random) ... ok test_asymmetry (test.test_math.IsCloseTests.test_asymmetry) ... ok test_decimals (test.test_math.IsCloseTests.test_decimals) ... ok test_eight_decimal_places (test.test_math.IsCloseTests.test_eight_decimal_places) ... ok test_fractions (test.test_math.IsCloseTests.test_fractions) ... ok test_identical (test.test_math.IsCloseTests.test_identical) ... ok test_identical_infinite (test.test_math.IsCloseTests.test_identical_infinite) ... ok test_inf_ninf_nan (test.test_math.IsCloseTests.test_inf_ninf_nan) ... ok test_integers (test.test_math.IsCloseTests.test_integers) ... ok test_near_zero (test.test_math.IsCloseTests.test_near_zero) ... ok test_negative_tolerances (test.test_math.IsCloseTests.test_negative_tolerances) ... ok test_zero_tolerance (test.test_math.IsCloseTests.test_zero_tolerance) ... ok testAcos (test.test_math.MathTests.testAcos) ... ok testAcosh (test.test_math.MathTests.testAcosh) ... ok testAsin (test.test_math.MathTests.testAsin) ... ok testAsinh (test.test_math.MathTests.testAsinh) ... ok testAtan (test.test_math.MathTests.testAtan) ... ok testAtan2 (test.test_math.MathTests.testAtan2) ... ok testAtanh (test.test_math.MathTests.testAtanh) ... ok testCbrt (test.test_math.MathTests.testCbrt) ... ok testCeil (test.test_math.MathTests.testCeil) ... ok testComb (test.test_math.MathTests.testComb) ... ok testConstants (test.test_math.MathTests.testConstants) ... ok testCopysign (test.test_math.MathTests.testCopysign) ... ok testCos (test.test_math.MathTests.testCos) ... ok testCosh (test.test_math.MathTests.testCosh) ... ok testDegrees (test.test_math.MathTests.testDegrees) ... ok testDist (test.test_math.MathTests.testDist) ... ok testExp (test.test_math.MathTests.testExp) ... ok testExp2 (test.test_math.MathTests.testExp2) ... ok testFabs (test.test_math.MathTests.testFabs) ... ok testFactorial (test.test_math.MathTests.testFactorial) ... ok testFactorialHugeInputs (test.test_math.MathTests.testFactorialHugeInputs) ... ok testFactorialNonIntegers (test.test_math.MathTests.testFactorialNonIntegers) ... ok testFloor (test.test_math.MathTests.testFloor) ... ok testFmod (test.test_math.MathTests.testFmod) ... ok testFrexp (test.test_math.MathTests.testFrexp) ... ok testFsum (test.test_math.MathTests.testFsum) ... ok testGcd (test.test_math.MathTests.testGcd) ... ok testHypot (test.test_math.MathTests.testHypot) ... ok testHypotAccuracy (test.test_math.MathTests.testHypotAccuracy) ... ok testIsfinite (test.test_math.MathTests.testIsfinite) ... ok testIsinf (test.test_math.MathTests.testIsinf) ... ok testIsnan (test.test_math.MathTests.testIsnan) ... ok testIsqrt (test.test_math.MathTests.testIsqrt) ... ok testLdexp (test.test_math.MathTests.testLdexp) ... ok testLog (test.test_math.MathTests.testLog) ... ok testLog10 (test.test_math.MathTests.testLog10) ... ok testLog1p (test.test_math.MathTests.testLog1p) ... ok testLog2 (test.test_math.MathTests.testLog2) ... ok testLog2Exact (test.test_math.MathTests.testLog2Exact) ... ok testModf (test.test_math.MathTests.testModf) ... ok testPerm (test.test_math.MathTests.testPerm) ... ok testPow (test.test_math.MathTests.testPow) ... ok testRadians (test.test_math.MathTests.testRadians) ... ok testRemainder (test.test_math.MathTests.testRemainder) ... ok testSin (test.test_math.MathTests.testSin) ... ok testSinh (test.test_math.MathTests.testSinh) ... ok testSqrt (test.test_math.MathTests.testSqrt) ... ok testSumProd (test.test_math.MathTests.testSumProd) ... ok testTan (test.test_math.MathTests.testTan) ... ok testTanh (test.test_math.MathTests.testTanh) ... ok testTanhSign (test.test_math.MathTests.testTanhSign) ... ok test_exceptions (test.test_math.MathTests.test_exceptions) ... ok test_inf_constant (test.test_math.MathTests.test_inf_constant) ... ok test_input_exceptions (test.test_math.MathTests.test_input_exceptions) ... ok test_issue39871 (test.test_math.MathTests.test_issue39871) ... ok test_lcm (test.test_math.MathTests.test_lcm) ... ok test_math_dist_leak (test.test_math.MathTests.test_math_dist_leak) ... ok test_mtestfile (test.test_math.MathTests.test_mtestfile) ... ok test_nan_constant (test.test_math.MathTests.test_nan_constant) ... ok test_nextafter (test.test_math.MathTests.test_nextafter) ... ok test_prod (test.test_math.MathTests.test_prod) ... ok test_sumprod_accuracy (test.test_math.MathTests.test_sumprod_accuracy) ... ok test_sumprod_extended_precision_accuracy (test.test_math.MathTests.test_sumprod_extended_precision_accuracy) ... ok test_sumprod_stress (test.test_math.MathTests.test_sumprod_stress) ... ok test_testfile (test.test_math.MathTests.test_testfile) ... ok test_trunc (test.test_math.MathTests.test_trunc) ... ok test_ulp (test.test_math.MathTests.test_ulp) ... ok /Python-3.13.2/Lib/test/mathdata/ieee754.txt Doctest: ieee754.txt ... ok ====================================================================== FAIL: test_fma_zero_result (test.test_math.FMATests.test_fma_zero_result) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Python-3.13.2/Lib/test/test_math.py", line 2744, in test_fma_zero_result self.assertIsNegativeZero(math.fma(tiny, -tiny, 0.0)) ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Python-3.13.2/Lib/test/test_math.py", line 2860, in assertIsNegativeZero self.assertTrue( ~~~~~~~~~~~~~~~^ value == 0 and math.copysign(1, value) < 0, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ msg="Expected a negative zero, got {!r}".format(value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ AssertionError: False is not true : Expected a negative zero, got 0.0 ---------------------------------------------------------------------- Ran 85 tests in 77.598s FAILED (failures=1)You're building a docker image using Alpine Linux which uses the musl C library. It seems like musl has a bug in the fma() function.
- changed the title
[-]Python 3.13 installation failing in docker:dind[/-][+]test_math.test_fma_zero_result() fails with the musl C library[/+]on Mar 11, 2025 - added a commit that references this issue
on Mar 11, 2025 is there any plan to release new version of python because of this change?
is there any plan to release new version of python because of this change?
My fix is not merged yet, and no, there will not be a new release just because of this fix.
You can tune the PGO task to ignore the failing test: see
PROFILE_TASKvariable in configure. Default:PROFILE_TASK= -m test --pgo --timeout=$(TESTTIMEOUT)You can ignore the failing test using
-ioption. Example:./configure --enable-optimizations PROFILE_TASK='-m test --pgo -i test_fma_zero_result'@prashanthallu, maybe you can try this patch?
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index b4c15a143f..39e34307dc 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -2344,7 +2344,19 @@ static PyObject * math_fma_impl(PyObject *module, double x, double y, double z) /*[clinic end generated code: output=4fc8626dbc278d17 input=e3ad1f4a4c89626e]*/ { - double r = fma(x, y, z); + double r; + + if (z) { + r = fma(x, y, z); + } + else { + if (x && y) { + r = x * y; + } + else { + r = copysign(1, z) == 1 ? x*y + z : x*y; + } + } /* Fast path: if we got a finite result, we're done. */ if (isfinite(r)) {
@prashanthallu, maybe you can try this patch?
This patch works with musl (test_math pass). Do you suggest to apply it on all platforms? musl has no
#ifdef.Do you suggest to apply it on all platforms?
I would think of it, if this really solves problem on a lot of platforms. It might be the case: no other fma tests are skipped, thus there is a chance that problems restricted to few corner cases.
- added a commit that references this issue
on Mar 12, 2025 Ok, I converted your patch to a PR: #131134. Let's see if test_math still pass on buildbots (ex: FreeBSD and WASI).
is there any plan to release new version of python because of this change?
My fix is not merged yet, and no, there will not be a new release just because of this fix.
You can tune the PGO task to ignore the failing test: see
PROFILE_TASKvariable in configure. Default:PROFILE_TASK= -m test --pgo --timeout=$(TESTTIMEOUT)You can ignore the failing test using
-ioption. Example:./configure --enable-optimizations PROFILE_TASK='-m test --pgo -i test_fma_zero_result'with the help of PROFILE_TASK able to skip the test case but still python is not able to install in docker:dind and attached the Python installation logs
413.9 0:01:24 load avg: 1.61 [35/44] test_re 415.0 test test_re failed 415.0 0:01:25 load avg: 1.61 [36/44] test_set -- test_re failed (2 failures)Again, you can please try to re-run test_re in verbose mode? Something like:
./python -m test test_re -v.7 remaining items
It is more complicated, because we can get zero result with wrong sign also for non-zero
z, and there are much more such cases. Fixing only case for zerozwill make matters worse, because the function will no longer be monotonic. Fixing it for all cases means re-implementing thefma()function. This is a lot of work, and the general implementation can be slower than the specialized C library implementation. AFAIK, when thefma()function was added, it was decided to not add our own implementation, but use the C library implementation. If it is flawed, let it be so. The specific test should be skipped on such platforms.because we can get zero result with wrong sign also for non-zero z, and there are much more such cases.
Maybe. Can you prove this with broken tests?
It's possible that on this platform - fma() not broken for non-zero arguments.
The specific test should be skipped on such platforms.
Yes, this is an alternative. In this case, test function must be split: it seems zero arguments aren't a problem for other platforms.
with the following command. I am able to install Python 3.13.2 version in docker:dind. Thank you @vstinner
./configure --enable-optimizations PROFILE_TASK='-m test --pgo -i test_fma_zero_result -i test_locale_caching -i test_locale_compiled'
What to prove? There is a test for
x = a + b,y = a - b,z = -a*a, wherea = 2**-500,b = 2**-550. The exact result ofx * y + zis-b*b, which underflows to-0.0. But iffma()uses 64-bit floating point for intermediate result ofx * y, it returns0.0. You can try other values ofaandb. It is very likely that you will get wrong result forb = 2**(-500-k), where k is from 27 to 52. It is even likely that you will get wrong result for many if not most of values ofbbetween2**-552and2**-527, not only for powers of 2. I am sure, that if you got wrong result for somexandy, you will get the same wrong result forx*2**jandy*2**-jfor somej. You can also find examples in form ofx*d,y/d, which will get similar wrong results for somed.If
fma()returns wrong zero result, it is very likely that some non-zero results are also wrong.In this case, test function must be split: it seems zero arguments aren't a problem for other platforms.
If assertions with zero and non-zero arguments fail on different platforms, we can split the test method. But we should not try to fix the implementation only for zero arguments.
- added a commit that references this issue
on Mar 13, 2025 What to prove? There is a test for x = a + b, y = a - b, z = -a*a, where a = 2**-500, b = 2**-550.
But it doesn't fail with musl C and above patch (which doesn't relevant in this case), see #131134.
If fma() returns wrong zero result, it is very likely that some non-zero results are also wrong.
Maybe. But our tests definitely lacks such case.
I merged my PR skipping tests if Python is linked to musl (PR gh-131071). I close this issue.
@prashanthallu: Would you mind to open a new issue for the two test_re failures? Thanks for your bug report.
AFAIK, when the fma() function was added, it was decided to not add our own implementation, but use the C library implementation. If it is flawed, let it be so. The specific test should be skipped on such platforms.
I agree with Serhiy.
Reacted by Eric V. Smith
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Bug report
Bug description:
While installing Python 3.13 version in docker:dind endingup without installation, getting the issue like as mentioned below
Which is happening in only docker:dind, when I am trying in centos, ubuntu able to install.
And one more with the Python 3.12.9 version able to install in in docker:dind and logs are
So what could be the issue ?.
I am using following Dockerfile code to install Python
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs