1#include "libm.h"
2
3double trunc(double x) {
4    union {
5        double f;
6        uint64_t i;
7    } u = {x};
8    int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
9    uint64_t m;
10
11    if (e >= 52 + 12)
12        return x;
13    if (e < 12)
14        e = 1;
15    m = -1ULL >> e;
16    if ((u.i & m) == 0)
17        return x;
18    FORCE_EVAL(x + 0x1p120f);
19    u.i &= ~m;
20    return u.f;
21}
22