| OLD | NEW |
| 1 #include <limits.h> | 1 #include <limits.h> |
| 2 #include <fenv.h> | 2 #include <fenv.h> |
| 3 #include "libm.h" | 3 #include "libm.h" |
| 4 | 4 |
| 5 | 5 |
| 6 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | 6 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
| 7 long long llrintl(long double x) | 7 long long llrintl(long double x) |
| 8 { | 8 { |
| 9 return llrint(x); | 9 return llrint(x); |
| 10 } | 10 } |
| 11 #elif defined(FE_INEXACT) | 11 #elif defined(FE_INEXACT) |
| 12 /* | 12 /* |
| 13 see comments in lrint.c | 13 see comments in lrint.c |
| 14 | 14 |
| 15 Note that if LLONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64 | 15 Note that if LLONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64 |
| 16 then x == 2**63 - 0.5 is the only input that overflows and | 16 then x == 2**63 - 0.5 is the only input that overflows and |
| 17 raises inexact (with tonearest or upward rounding mode) | 17 raises inexact (with tonearest or upward rounding mode) |
| 18 */ | 18 */ |
| 19 long long llrintl(long double x) | 19 long long llrintl(long double x) |
| 20 { | 20 { |
| 21 » #pragma STDC FENV_ACCESS ON | 21 » PRAGMA_STDC_FENV_ACCESS_ON |
| 22 int e; | 22 int e; |
| 23 | 23 |
| 24 e = fetestexcept(FE_INEXACT); | 24 e = fetestexcept(FE_INEXACT); |
| 25 x = rintl(x); | 25 x = rintl(x); |
| 26 if (!e && (x > LLONG_MAX || x < LLONG_MIN)) | 26 if (!e && (x > LLONG_MAX || x < LLONG_MIN)) |
| 27 feclearexcept(FE_INEXACT); | 27 feclearexcept(FE_INEXACT); |
| 28 /* conversion */ | 28 /* conversion */ |
| 29 return x; | 29 return x; |
| 30 } | 30 } |
| 31 #else | 31 #else |
| 32 long long llrintl(long double x) | 32 long long llrintl(long double x) |
| 33 { | 33 { |
| 34 return rintl(x); | 34 return rintl(x); |
| 35 } | 35 } |
| 36 #endif | 36 #endif |
| OLD | NEW |