]> git.proxmox.com Git - wasi-libc.git/blobdiff - libc-top-half/musl/src/math/fmaf.c
Update to musl 1.2.3.
[wasi-libc.git] / libc-top-half / musl / src / math / fmaf.c
index 111c0aec986ee249cdd06e5af98c738657e5549c..7c65acf1fc5e07eabcad635b31af3ee747319106 100644 (file)
@@ -77,21 +77,16 @@ float fmaf(float x, float y, float z)
         * If result is inexact, and exactly halfway between two float values,
         * we need to adjust the low-order bit in the direction of the error.
         */
-#ifdef FE_TOWARDZERO
-       fesetround(FE_TOWARDZERO);
-#endif
-#ifdef __wasilibc_unmodified_upstream // WASI doesn't need old GCC workarounds
-       volatile double vxy = xy;  /* XXX work around gcc CSE bug */
-#else
-       double vxy = xy;
-#endif
-       double adjusted_result = vxy + z;
-       fesetround(FE_TONEAREST);
-       if (result == adjusted_result) {
-               u.f = adjusted_result;
+       double err;
+       int neg = u.i >> 63;
+       if (neg == (z > xy))
+               err = xy - result + z;
+       else
+               err = z - result + xy;
+       if (neg == (err < 0))
                u.i++;
-               adjusted_result = u.f;
-       }
-       z = adjusted_result;
+       else
+               u.i--;
+       z = u.f;
        return z;
 }