1 #include "libm.h"
2 
3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
truncl(long double x)4 long double truncl(long double x) {
5     return trunc(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 
truncl(long double x)11 long double truncl(long double x) {
12     union ldshape u = {x};
13     int e = u.i.se & 0x7fff;
14     int s = u.i.se >> 15;
15     long double y;
16 
17     if (e >= 0x3fff + LDBL_MANT_DIG - 1)
18         return x;
19     if (e <= 0x3fff - 1) {
20         FORCE_EVAL(x + 0x1p120f);
21         return x * 0;
22     }
23     /* y = int(|x|) - |x|, where int(|x|) is an integer neighbor of |x| */
24     if (s)
25         x = -x;
26     y = x + toint - toint - x;
27     if (y > 0)
28         y -= 1;
29     x += y;
30     return s ? -x : x;
31 }
32 #endif
33