add PTHREAD_NULL
[musl.git] / src / math / modfl.c
bloba47b1924f75d1125b712e3ccf5b0f39af27fd8f2
1 #include "libm.h"
3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
4 long double modfl(long double x, long double *iptr)
6 double d;
7 long double r;
9 r = modf(x, &d);
10 *iptr = d;
11 return r;
13 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
15 static const long double toint = 1/LDBL_EPSILON;
17 long double modfl(long double x, long double *iptr)
19 union ldshape u = {x};
20 int e = (u.i.se & 0x7fff) - 0x3fff;
21 int s = u.i.se >> 15;
22 long double absx;
23 long double y;
25 /* no fractional part */
26 if (e >= LDBL_MANT_DIG-1) {
27 *iptr = x;
28 if (isnan(x))
29 return x;
30 return s ? -0.0 : 0.0;
33 /* no integral part*/
34 if (e < 0) {
35 *iptr = s ? -0.0 : 0.0;
36 return x;
39 /* raises spurious inexact */
40 absx = s ? -x : x;
41 y = absx + toint - toint - absx;
42 if (y == 0) {
43 *iptr = x;
44 return s ? -0.0 : 0.0;
46 if (y > 0)
47 y -= 1;
48 if (s)
49 y = -y;
50 *iptr = x + y;
51 return -y;
53 #endif