nsz | 9560b6b | 2012-03-13 19:51:14 +0100 | [diff] [blame] | 1 | #include <math.h> |
2 | #include <float.h> | ||||
3 | |||||
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
5 | long double nearbyintl(long double x) | ||||
6 | { | ||||
7 | return nearbyint(x); | ||||
8 | } | ||||
9 | #else | ||||
10 | #include <fenv.h> | ||||
11 | long double nearbyintl(long double x) | ||||
12 | { | ||||
nsz | 91c28f6 | 2012-03-20 22:49:19 +0100 | [diff] [blame] | 13 | #ifdef FE_INEXACT |
Szabolcs Nagy | 033a9d6 | 2012-11-13 13:34:45 +0100 | [diff] [blame] | 14 | #pragma STDC FENV_ACCESS ON |
nsz | 91c28f6 | 2012-03-20 22:49:19 +0100 | [diff] [blame] | 15 | int e; |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 16 | |
nsz | 91c28f6 | 2012-03-20 22:49:19 +0100 | [diff] [blame] | 17 | e = fetestexcept(FE_INEXACT); |
18 | #endif | ||||
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 19 | x = rintl(x); |
nsz | 91c28f6 | 2012-03-20 22:49:19 +0100 | [diff] [blame] | 20 | #ifdef FE_INEXACT |
21 | if (!e) | ||||
22 | feclearexcept(FE_INEXACT); | ||||
23 | #endif | ||||
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 24 | return x; |
25 | } | ||||
26 | #endif |