diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-03-20 19:51:11 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-03-20 19:51:11 -0400 |
commit | 58bf74850f5f7286dc290aa22ad982f50620a1c8 (patch) | |
tree | ad1d29dbdd40b13381f860f8900f8b0673dfa689 /src/math/nearbyint.c | |
parent | ad47d45e9da8df364cb0a61b6146d51c196c8891 (diff) | |
parent | 91c28f61f43ba029166772e8ac25808ea3c3dc98 (diff) | |
download | musl-58bf74850f5f7286dc290aa22ad982f50620a1c8.tar.gz |
Merge remote branch 'nsz/master'
Diffstat (limited to 'src/math/nearbyint.c')
-rw-r--r-- | src/math/nearbyint.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/math/nearbyint.c b/src/math/nearbyint.c index 714c55ca..7a4c58cf 100644 --- a/src/math/nearbyint.c +++ b/src/math/nearbyint.c @@ -1,20 +1,19 @@ #include <fenv.h> #include <math.h> -/* -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 + 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; } |