blob: 9a7703c7db19bbc2baded7bb75efca50a1e267f0 [file] [log] [blame]
Viet-Trung Luu96b05c12016-01-11 11:26:36 -08001#include "libm.h"
2
3#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
George Kulakowski17e3b042016-02-18 15:59:50 -08004long double floorl(long double x) {
5 return floor(x);
Viet-Trung Luu96b05c12016-01-11 11:26:36 -08006}
7#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
8
George Kulakowski17e3b042016-02-18 15:59:50 -08009static const long double toint = 1 / LDBL_EPSILON;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080010
George Kulakowski17e3b042016-02-18 15:59:50 -080011long double floorl(long double x) {
12 union ldshape u = {x};
13 int e = u.i.se & 0x7fff;
14 long double y;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080015
George Kulakowski17e3b042016-02-18 15:59:50 -080016 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 ? -1 : 0;
27 }
28 if (y > 0)
29 return x + y - 1;
30 return x + y;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080031}
32#endif