aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2024-03-19 14:31:39 +0000
committerEd Maste <emaste@FreeBSD.org>2024-06-08 15:55:36 +0000
commit888796ade2842486d3167067e8034254c38aadd3 (patch)
treed235c9aa6238dac01c0b4bd7434cb782560e60b0
parent5ee5c40402c92a498ed8d6eeb6cf0b5c1680817b (diff)
downloadsrc-888796ade2842486d3167067e8034254c38aadd3.tar.gz
src-888796ade2842486d3167067e8034254c38aadd3.zip
libm: fma: correct zero sign with small inputs
PR: 277783 Reported by: Victor Stinner Submitted by: kargl MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D44433
-rw-r--r--lib/msun/src/s_fma.c4
-rw-r--r--lib/msun/src/s_fmal.c4
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/msun/src/s_fma.c b/lib/msun/src/s_fma.c
index b8a342646d85..4d08b40cc71a 100644
--- a/lib/msun/src/s_fma.c
+++ b/lib/msun/src/s_fma.c
@@ -267,7 +267,9 @@ fma(double x, double y, double z)
*/
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) {
diff --git a/lib/msun/src/s_fmal.c b/lib/msun/src/s_fmal.c
index 3d333632127c..12f9c364670b 100644
--- a/lib/msun/src/s_fmal.c
+++ b/lib/msun/src/s_fmal.c
@@ -248,7 +248,9 @@ fmal(long double x, long double y, long double z)
*/
fesetround(oround);
volatile long double vzs = zs; /* XXX gcc CSE bug workaround */
- return (xy.hi + vzs + ldexpl(xy.lo, spread));
+ xs = ldexpl(xy.lo, spread);
+ xy.hi += vzs;
+ return (xy.hi == 0 ? xs : xy.hi + xs);
}
if (oround != FE_TONEAREST) {