[Bug 277783] libc fma() doesn't not return the correct zero sign
- In reply to: bugzilla-noreply_a_freebsd.org: "[Bug 277783] libc fma() doesn't not return the correct zero sign"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 18 Mar 2024 21:06:29 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277783 --- Comment #4 from Steve Kargl <kargl@FreeBSD.org> --- Ok, with the given input to fma, one arrives at line 271 return (xy.hi + vzs + ldexp(xy.lo, spread)); (gdb) p vzs $12 = -0.5 (gdb) p xy.hi $13 = 0.5 (gdb) p xy.lo $14 = -3.944304526105059e-31 (gdb) p spread $15 = -999 Turns out that ldexp(3.944304526105059e-31, -999) = -0x0p+0. So, you have 0.5 - 0.5 - 0. = 0. - 0. = +0 So, a pessimestic patch is Index: src/s_fma.c =================================================================== --- src/s_fma.c (revision 2834) +++ src/s_fma.c (working copy) @@ -267,7 +267,9 @@ */ fesetround(oround); volatile double vzs = zs; /* XXX gcc CSE bug workaround */ - return (xy.hi + vzs + ldexp(xy.lo, spread)); + xs = ldexp(xy.lo, spread); + xy.hi += vzs; + return (xy.hi == 0 ? xs : xy.hi + xs); } if (oround != FE_TONEAREST) { -- You are receiving this mail because: You are the assignee for the bug.