| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | #include "libm.h" |
| 16 | #if (LDBL_MANT_DIG64 == 64 || LDBL_MANT_DIG64 == 113) && LDBL_MAX_EXP16384 == 16384 |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | static const long double toint = 1.5/LDBL_EPSILON1.0842021724855044340e-19L; |
| 24 | |
| 25 | #if LDBL_MANT_DIG64 == 64 |
| 26 | |
| 27 | #define SMALL(u)(((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < (( 0x3fff + 25)<<16 | 0x921f>>1 | 0x8000)) (((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < ((0x3fff + 25)<<16 | 0x921f>>1 | 0x8000)) |
| 28 | #define QUOBITS(x)((uint32_t)(int32_t)x & 0x7fffffff) ((uint32_t)(int32_t)x & 0x7fffffff) |
| 29 | #define ROUND122 22 |
| 30 | #define ROUND261 61 |
| 31 | #define NX3 3 |
| 32 | #define NY2 2 |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | static const double |
| 43 | pio2_1 = 1.57079632679597125389e+00, |
| 44 | pio2_2 = -1.07463465549783099519e-12, |
| 45 | pio2_3 = 6.36831716351370313614e-25; |
| 46 | static const long double |
| 47 | invpio2 = 6.36619772367581343076e-01L, |
| 48 | pio2_1t = -1.07463465549719416346e-12L, |
| 49 | pio2_2t = 6.36831716351095013979e-25L, |
| 50 | pio2_3t = -2.75299651904407171810e-37L; |
| 51 | #elif LDBL_MANT_DIG64 == 113 |
| 52 | |
| 53 | #define SMALL(u)(((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < (( 0x3fff + 25)<<16 | 0x921f>>1 | 0x8000)) (((u.i.se & 0x7fffU)<<16 | u.i.top) < ((0x3fff + 45)<<16 | 0x921f)) |
| 54 | #define QUOBITS(x)((uint32_t)(int32_t)x & 0x7fffffff) ((uint32_t)(int64_t)x & 0x7fffffff) |
| 55 | #define ROUND122 51 |
| 56 | #define ROUND261 119 |
| 57 | #define NX3 5 |
| 58 | #define NY2 3 |
| 59 | static const long double |
| 60 | invpio2 = 6.3661977236758134307553505349005747e-01L, |
| 61 | pio2_1 = 1.5707963267948966192292994253909555e+00L, |
| 62 | pio2_1t = 2.0222662487959507323996846200947577e-21L, |
| 63 | pio2_2 = 2.0222662487959507323994779168837751e-21L, |
| 64 | pio2_2t = 2.0670321098263988236496903051604844e-43L, |
| 65 | pio2_3 = 2.0670321098263988236499468110329591e-43L, |
| 66 | pio2_3t = -2.5650587247459238361625433492959285e-65L; |
| 67 | #endif |
| 68 | |
| 69 | int __rem_pio2l(long double x, long double *y) |
| 70 | { |
| 71 | union ldshape u,uz; |
| 72 | long double z,w,t,r,fn; |
| 73 | double tx[NX3],ty[NY2]; |
| 74 | int ex,ey,n,i; |
| 75 | |
| 76 | u.f = x; |
| 77 | ex = u.i.se & 0x7fff; |
| 78 | if (SMALL(u)(((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < (( 0x3fff + 25)<<16 | 0x921f>>1 | 0x8000))) { |
| |
| 79 | |
| 80 | fn = x*invpio2 + toint - toint; |
| 81 | n = QUOBITS(fn)((uint32_t)(int32_t)fn & 0x7fffffff); |
| 82 | r = x-fn*pio2_1; |
| 83 | w = fn*pio2_1t; |
| 84 | y[0] = r-w; |
| 85 | u.f = y[0]; |
| 86 | ey = u.i.se & 0x7fff; |
| 87 | if (ex - ey > ROUND122) { |
| 88 | t = r; |
| 89 | w = fn*pio2_2; |
| 90 | r = t-w; |
| 91 | w = fn*pio2_2t-((t-r)-w); |
| 92 | y[0] = r-w; |
| 93 | u.f = y[0]; |
| 94 | ey = u.i.se & 0x7fff; |
| 95 | if (ex - ey > ROUND261) { |
| 96 | t = r; |
| 97 | w = fn*pio2_3; |
| 98 | r = t-w; |
| 99 | w = fn*pio2_3t-((t-r)-w); |
| 100 | y[0] = r-w; |
| 101 | } |
| 102 | } |
| 103 | y[1] = (r - y[0]) - w; |
| 104 | return n; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | |
| 109 | if (ex == 0x7fff) { |
| 2 | | Assuming 'ex' is not equal to 32767 | |
|
| |
| 110 | y[0] = y[1] = x - x; |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | uz.f = x; |
| 115 | uz.i.se = 0x3fff + 23; |
| 116 | z = uz.f; |
| 117 | for (i=0; i < NX3 - 1; i++) { |
| 4 | | Loop condition is true. Entering loop body | |
|
| 5 | | Loop condition is true. Entering loop body | |
|
| 6 | | Loop condition is false. Execution continues on line 121 | |
|
| 118 | tx[i] = (double)(int32_t)z; |
| 119 | z = (z-tx[i])*0x1p24; |
| 120 | } |
| 121 | tx[i] = z; |
| 122 | while (tx[i] == 0) |
| 7 | | Loop condition is true. Entering loop body | |
|
| 8 | | Loop condition is true. Entering loop body | |
|
| 9 | | Loop condition is true. Entering loop body | |
|
| 10 | | The left operand of '==' is a garbage value |
|
| 123 | i--; |
| 124 | n = __rem_pio2_large(tx, ty, ex-0x3fff-23, i+1, NY2); |
| 125 | w = ty[1]; |
| 126 | if (NY2 == 3) |
| 127 | w += ty[2]; |
| 128 | r = ty[0] + w; |
| 129 | |
| 130 | |
| 131 | w -= r - ty[0]; |
| 132 | if (u.i.se >> 15) { |
| 133 | y[0] = -r; |
| 134 | y[1] = -w; |
| 135 | return -n; |
| 136 | } |
| 137 | y[0] = r; |
| 138 | y[1] = w; |
| 139 | return n; |
| 140 | } |
| 141 | #endif |