X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmath%2Ffma.c;h=741ccd757ab1544d5ed4d6fd2bd135d7cb0586e3;hb=5fc1487832e16aa2119e735a388d5f36c8c139e2;hp=84868be5d354144bcd56833bc12994a44b70fea9;hpb=63b9cc777323488da3474e8bc53e0ac4d3521382;p=musl diff --git a/src/math/fma.c b/src/math/fma.c index 84868be5..741ccd75 100644 --- a/src/math/fma.c +++ b/src/math/fma.c @@ -273,7 +273,7 @@ static inline double add_and_denormalize(double a, double b, int scale) if (sum.lo != 0) { uhi.f = sum.hi; bits_lost = -((int)(uhi.i >> 52) & 0x7ff) - scale + 1; - if (bits_lost != 1 ^ (int)(uhi.i & 1)) { + if ((bits_lost != 1) ^ (int)(uhi.i & 1)) { /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */ ulo.f = sum.lo; uhi.i += 1 - (((uhi.i ^ ulo.i) >> 62) & 2); @@ -431,12 +431,24 @@ double fma(double x, double y, double z) /* * There is no need to worry about double rounding in directed * rounding modes. - * TODO: underflow is not raised properly, example in downward rounding: + * But underflow may not be raised properly, example in downward rounding: * fma(0x1.000000001p-1000, 0x1.000000001p-30, -0x1p-1066) */ + double ret; +#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) + int e = fetestexcept(FE_INEXACT); + feclearexcept(FE_INEXACT); +#endif fesetround(oround); adj = r.lo + xy.lo; - return scalbn(r.hi + adj, spread); + ret = scalbn(r.hi + adj, spread); +#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) + if (ilogb(ret) < -1022 && fetestexcept(FE_INEXACT)) + feraiseexcept(FE_UNDERFLOW); + else if (e) + feraiseexcept(FE_INEXACT); +#endif + return ret; } adj = add_adjusted(r.lo, xy.lo);