OLD | NEW |
1 #include "libm.h" | 1 #include "libm.h" |
2 | 2 |
3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | 3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
4 long double modfl(long double x, long double *iptr) | 4 long double modfl(long double x, long double* iptr) { |
5 { | 5 double d; |
6 » double d; | 6 long double r; |
7 » long double r; | |
8 | 7 |
9 » r = modf(x, &d); | 8 r = modf(x, &d); |
10 » *iptr = d; | 9 *iptr = d; |
11 » return r; | 10 return r; |
12 } | 11 } |
13 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | 12 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 |
14 | 13 |
15 static const long double toint = 1/LDBL_EPSILON; | 14 static const long double toint = 1 / LDBL_EPSILON; |
16 | 15 |
17 long double modfl(long double x, long double *iptr) | 16 long double modfl(long double x, long double* iptr) { |
18 { | 17 union ldshape u = {x}; |
19 » union ldshape u = {x}; | 18 int e = (u.i.se & 0x7fff) - 0x3fff; |
20 » int e = (u.i.se & 0x7fff) - 0x3fff; | 19 int s = u.i.se >> 15; |
21 » int s = u.i.se >> 15; | 20 long double absx; |
22 » long double absx; | 21 long double y; |
23 » long double y; | |
24 | 22 |
25 » /* no fractional part */ | 23 /* no fractional part */ |
26 » if (e >= LDBL_MANT_DIG-1) { | 24 if (e >= LDBL_MANT_DIG - 1) { |
27 » » *iptr = x; | 25 *iptr = x; |
28 » » if (isnan(x)) | 26 if (isnan(x)) |
29 » » » return x; | 27 return x; |
30 » » return s ? -0.0 : 0.0; | 28 return s ? -0.0 : 0.0; |
31 » } | 29 } |
32 | 30 |
33 » /* no integral part*/ | 31 /* no integral part*/ |
34 » if (e < 0) { | 32 if (e < 0) { |
35 » » *iptr = s ? -0.0 : 0.0; | 33 *iptr = s ? -0.0 : 0.0; |
36 » » return x; | 34 return x; |
37 » } | 35 } |
38 | 36 |
39 » /* raises spurious inexact */ | 37 /* raises spurious inexact */ |
40 » absx = s ? -x : x; | 38 absx = s ? -x : x; |
41 » y = absx + toint - toint - absx; | 39 y = absx + toint - toint - absx; |
42 » if (y == 0) { | 40 if (y == 0) { |
43 » » *iptr = x; | 41 *iptr = x; |
44 » » return s ? -0.0 : 0.0; | 42 return s ? -0.0 : 0.0; |
45 » } | 43 } |
46 » if (y > 0) | 44 if (y > 0) |
47 » » y -= 1; | 45 y -= 1; |
48 » if (s) | 46 if (s) |
49 » » y = -y; | 47 y = -y; |
50 » *iptr = x + y; | 48 *iptr = x + y; |
51 » return -y; | 49 return -y; |
52 } | 50 } |
53 #endif | 51 #endif |
OLD | NEW |