0e579bc51c9a4066e7a0b197614c6f9ad6a458b2
[musl] / src / math / lrintl.c
1 #include <limits.h>
2 #include <fenv.h>
3 #include "libm.h"
4
5
6 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
7 long lrintl(long double x)
8 {
9         return lrint(x);
10 }
11 #else
12 /*
13 see comments in lrint.c
14
15 Note that if LONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64
16 then x == 2**63 - 0.5 is the only input that overflows and
17 raises inexact (with tonearest or upward rounding mode)
18 */
19 long lrintl(long double x)
20 {
21         int e;
22
23         e = fetestexcept(FE_INEXACT);
24         x = rintl(x);
25         if (!e && (x > LONG_MAX || x < LONG_MIN))
26                 feclearexcept(FE_INEXACT);
27         /* conversion */
28         return x;
29 }
30 #endif