1 #include "libm.h"
2 
3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
ceill(long double x)4 long double ceill(long double x) {
5     return ceil(x);
6 }
7 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
8 
9 static const long double toint = 1 / LDBL_EPSILON;
10 
ceill(long double x)11 long double ceill(long double x) {
12     union ldshape u = {x};
13     int e = u.i.se & 0x7fff;
14     long double y;
15 
16     if (e >= 0x3fff + LDBL_MANT_DIG - 1 || x == 0)
17         return x;
18     /* y = int(x) - x, where int(x) is an integer neighbor of x */
19     if (u.i.se >> 15)
20         y = x - toint + toint - x;
21     else
22         y = x + toint - toint - x;
23     /* special case because of non-nearest rounding modes */
24     if (e <= 0x3fff - 1) {
25         FORCE_EVAL(y);
26         return u.i.se >> 15 ? -0.0 : 1;
27     }
28     if (y < 0)
29         return x + y + 1;
30     return x + y;
31 }
32 #endif
33