math: rewrite modf.c and clean up modff.c
[musl] / src / math / fma.c
index a9de2cb..5fb9540 100644 (file)
@@ -23,10 +23,6 @@ static void add(long double *hi, long double *lo, long double x, long double y)
        *lo = y - r;
 }
 
-/*
-TODO(nsz): probably simpler mul is enough if we assume x and y are doubles
-so last 11bits are all zeros, no subnormals etc
-*/
 /* exact mul, assumes no over/underflow */
 static void mul(long double *hi, long double *lo, long double x, long double y)
 {
@@ -115,7 +111,7 @@ double fma(double x, double y, double z)
                add(&hi, &lo2, xy, z);
                if (hi == 0) {
                        fesetround(round);
-                       /* TODO: verify that the sign of 0 is always correct */
+                       /* make sure that the sign of 0 is correct */
                        return (xy + z) + lo1;
                }
        } else {
@@ -251,7 +247,7 @@ static inline double add_and_denormalize(double a, double b, int scale)
                        INSERT_WORD64(sum.hi, hibits);
                }
        }
-       return (ldexp(sum.hi, scale));
+       return scalbn(sum.hi, scale);
 }
 
 /*
@@ -368,7 +364,7 @@ double fma(double x, double y, double z)
                }
        }
        if (spread <= DBL_MANT_DIG * 2)
-               zs = ldexp(zs, -spread);
+               zs = scalbn(zs, -spread);
        else
                zs = copysign(DBL_MIN, zs);
 
@@ -394,7 +390,7 @@ double 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));
+               return xy.hi + vzs + scalbn(xy.lo, spread);
        }
 
        if (oround != FE_TONEAREST) {
@@ -404,13 +400,13 @@ double fma(double x, double y, double z)
                 */
                fesetround(oround);
                adj = r.lo + xy.lo;
-               return (ldexp(r.hi + adj, spread));
+               return scalbn(r.hi + adj, spread);
        }
 
        adj = add_adjusted(r.lo, xy.lo);
        if (spread + ilogb(r.hi) > -1023)
-               return (ldexp(r.hi + adj, spread));
+               return scalbn(r.hi + adj, spread);
        else
-               return (add_and_denormalize(r.hi, adj, spread));
+               return add_and_denormalize(r.hi, adj, spread);
 }
 #endif