X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmath%2Fnearbyint.c;h=f4e8aac4f0118d7d48d1d6a8e4af0fec048ee62a;hb=697acde67e0da4d73b46445ed536fe9923d515c7;hp=781769fba89c8850933997505bf5d943ea6fcbcd;hpb=b69f695acedd4ce2798ef9ea28d834ceccc789bd;p=musl diff --git a/src/math/nearbyint.c b/src/math/nearbyint.c index 781769fb..f4e8aac4 100644 --- a/src/math/nearbyint.c +++ b/src/math/nearbyint.c @@ -1,20 +1,20 @@ #include -#include "libm.h" +#include -/* -rint may raise inexact (and it should not alter the fenv otherwise) -nearbyint must not raise inexact +/* nearbyint is the same as rint, but it must not raise the inexact exception */ -(according to ieee754r section 7.9 both functions should raise invalid -when the input is signaling nan, but c99 does not define snan so saving -and restoring the entire fenv should be fine) -*/ +double nearbyint(double x) +{ +#ifdef FE_INEXACT + #pragma STDC FENV_ACCESS ON + int e; -double nearbyint(double x) { - fenv_t e; - - fegetenv(&e); + e = fetestexcept(FE_INEXACT); +#endif x = rint(x); - fesetenv(&e); +#ifdef FE_INEXACT + if (!e) + feclearexcept(FE_INEXACT); +#endif return x; }