![]() |
|
Message-ID: <20250311131032.GB1827@brightrain.aerifal.cx> Date: Tue, 11 Mar 2025 09:10:32 -0400 From: Rich Felker <dalias@...c.org> To: Victor Stinner <vstinner@...hon.org> Cc: musl@...ts.openwall.com Subject: Re: Bug in fma(): should return negative zero On Tue, Mar 11, 2025 at 12:30:58PM +0100, Victor Stinner wrote: > Hi, > > test_math.test_fma_zero_result() of Python 3.13 fails when Python is > built with musl: > https://github.com/python/cpython/issues/131032 > > The problem is that fma() returns +0.0 instead of -0.0 on some tests. > > Example: > --- > #include <math.h> > #include <stdio.h> > > int main(int argc, char **argv) > { > double tiny = 1e-300; > double zero = 0.0; > double result = fma(tiny, -tiny, zero); > printf("fma(%+g, %+g, %+g) = %+g\n", tiny, -tiny, zero, result); > return 0; > } > --- > > Output on Alpine with musl-1.2.5-r9: > --- > $ gcc x.c -Og -o x -lm && ./x > fma(+1e-300, -1e-300, +0) = +0 > --- > > Expected output: > --- > fma(+1e-300, -1e-300, +0) = -0 > --- > > Last year, I reported a similar bug to FreeBSD which was fixed: > https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277783 > > Link to Python test_fma_zero_result(): > https://github.com/python/cpython/blob/425e0af74fb882b95f81923123bd4afad0cda157/Lib/test/test_math.py#L2762-L2816 > > Tell me if you need more details. What archs have you tested it on? It doesn't happen for me and the general C code looks like it handles this case correctly, so I think there must be broken asm for one or more archs which doesn't honor this part of the fma contract right (due to broken cpu insn that doesn't match IEEE semantics). Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.