~ubuntu-branches/ubuntu/wily/musl/wily

« back to all changes in this revision

Viewing changes to src/math/exp2f.c

  • Committer: Package Import Robot
  • Author(s): Kevin Bortis
  • Date: 2013-09-27 23:47:18 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130927234718-a96bgcnvzx5buf60
Tags: 0.9.14-1
* Import upstream version 0.9.14
* Only build on fully supported architectures
* Point to new homepage in control file (Closes: #724277)
* Revorked debian/rules
* Solved possible problem with postrm script (Closes: #724247)

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
 * Method: (equally-spaced tables)
64
64
 *
65
65
 *   Reduce x:
66
 
 *     x = 2**k + y, for integer k and |y| <= 1/2.
 
66
 *     x = k + y, for integer k and |y| <= 1/2.
67
67
 *     Thus we have exp2f(x) = 2**k * exp2(y).
68
68
 *
69
69
 *   Reduce y:
83
83
 */
84
84
float exp2f(float x)
85
85
{
86
 
        double tv, twopk, u, z;
87
 
        float t;
88
 
        uint32_t hx, ix, i0, k;
 
86
        double_t t, r, z;
 
87
        union {float f; uint32_t i;} u = {x};
 
88
        union {double f; uint64_t i;} uk;
 
89
        uint32_t ix, i0, k;
89
90
 
90
91
        /* Filter out exceptional cases. */
91
 
        GET_FLOAT_WORD(hx, x);
92
 
        ix = hx & 0x7fffffff;
93
 
        if (ix >= 0x43000000) {  /* |x| >= 128 */
94
 
                if (ix >= 0x7f800000) {
95
 
                        if (hx == 0xff800000) /* -inf */
 
92
        ix = u.i & 0x7fffffff;
 
93
        if (ix > 0x42fc0000) {  /* |x| > 126 */
 
94
                if (u.i >= 0x43000000 && u.i < 0x80000000) {  /* x >= 128 */
 
95
                        x *= 0x1p127f;
 
96
                        return x;
 
97
                }
 
98
                if (u.i >= 0x80000000) {  /* x < -126 */
 
99
                        if (u.i >= 0xc3160000 || (u.i & 0x0000ffff))
 
100
                                FORCE_EVAL(-0x1p-149f/x);
 
101
                        if (u.i >= 0xc3160000)  /* x <= -150 */
96
102
                                return 0;
97
 
                        return x;
98
 
                }
99
 
                if (x >= 128) {
100
 
                        STRICT_ASSIGN(float, x, x * 0x1p127f);
101
 
                        return x;
102
 
                }
103
 
                if (x <= -150) {
104
 
                        STRICT_ASSIGN(float, x, 0x1p-100f*0x1p-100f);
105
 
                        return x;
106
103
                }
107
104
        } else if (ix <= 0x33000000) {  /* |x| <= 0x1p-25 */
108
105
                return 1.0f + x;
109
106
        }
110
107
 
111
108
        /* Reduce x, computing z, i0, and k. */
112
 
        STRICT_ASSIGN(float, t, x + redux);
113
 
        GET_FLOAT_WORD(i0, t);
 
109
        u.f = x + redux;
 
110
        i0 = u.i;
114
111
        i0 += TBLSIZE / 2;
115
 
        k = (i0 / TBLSIZE) << 20;
 
112
        k = i0 / TBLSIZE;
 
113
        uk.i = (uint64_t)(0x3ff + k)<<52;
116
114
        i0 &= TBLSIZE - 1;
117
 
        t -= redux;
118
 
        z = x - t;
119
 
        INSERT_WORDS(twopk, 0x3ff00000 + k, 0);
120
 
 
 
115
        u.f -= redux;
 
116
        z = x - u.f;
121
117
        /* Compute r = exp2(y) = exp2ft[i0] * p(z). */
122
 
        tv = exp2ft[i0];
123
 
        u = tv * z;
124
 
        tv = tv + u * (P1 + z * P2) + u * (z * z) * (P3 + z * P4);
 
118
        r = exp2ft[i0];
 
119
        t = r * z;
 
120
        r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
125
121
 
126
 
        /* Scale by 2**(k>>20). */
127
 
        return tv * twopk;
 
122
        /* Scale by 2**k */
 
123
        return r * uk.f;
128
124
}