s_exp2f.c (86c2e0c047d762127e31ac7510188ba436d299f3) | s_exp2f.c (684217d8896437b642fa8a6020bb5318b2c330ed) |
---|---|
1/*- 2 * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD$"); 29 | 1/*- 2 * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD$"); 29 |
30#include <float.h> 31 |
|
30#include "math.h" 31#include "math_private.h" 32 33#define TBLBITS 4 34#define TBLSIZE (1 << TBLBITS) 35 36static const float 37 huge = 0x1p100f, --- 48 unchanged lines hidden (view full) --- 86 * 87 * Tang, P. Table-driven Implementation of the Exponential Function 88 * in IEEE Floating-Point Arithmetic. TOMS 15(2), 144-157 (1989). 89 */ 90float 91exp2f(float x) 92{ 93 double tv; | 32#include "math.h" 33#include "math_private.h" 34 35#define TBLBITS 4 36#define TBLSIZE (1 << TBLBITS) 37 38static const float 39 huge = 0x1p100f, --- 48 unchanged lines hidden (view full) --- 88 * 89 * Tang, P. Table-driven Implementation of the Exponential Function 90 * in IEEE Floating-Point Arithmetic. TOMS 15(2), 144-157 (1989). 91 */ 92float 93exp2f(float x) 94{ 95 double tv; |
94 float r, z; 95 volatile float t; /* prevent gcc from using too much precision */ | 96 float r, t, z; |
96 uint32_t hx, hr, ix, i0; 97 int32_t k; 98 99 /* Filter out exceptional cases. */ 100 GET_FLOAT_WORD(hx,x); 101 ix = hx & 0x7fffffff; /* high word of |x| */ 102 if(ix >= 0x43000000) { /* |x| >= 128 */ 103 if(ix >= 0x7f800000) { --- 6 unchanged lines hidden (view full) --- 110 return (huge * huge); /* overflow */ 111 if(x <= -0x1.2cp7f) 112 return (twom100 * twom100); /* underflow */ 113 } else if (ix <= 0x33000000) { /* |x| <= 0x1p-25 */ 114 return (1.0f + x); 115 } 116 117 /* Reduce x, computing z, i0, and k. */ | 97 uint32_t hx, hr, ix, i0; 98 int32_t k; 99 100 /* Filter out exceptional cases. */ 101 GET_FLOAT_WORD(hx,x); 102 ix = hx & 0x7fffffff; /* high word of |x| */ 103 if(ix >= 0x43000000) { /* |x| >= 128 */ 104 if(ix >= 0x7f800000) { --- 6 unchanged lines hidden (view full) --- 111 return (huge * huge); /* overflow */ 112 if(x <= -0x1.2cp7f) 113 return (twom100 * twom100); /* underflow */ 114 } else if (ix <= 0x33000000) { /* |x| <= 0x1p-25 */ 115 return (1.0f + x); 116 } 117 118 /* Reduce x, computing z, i0, and k. */ |
118 t = x + redux; | 119 STRICT_ASSIGN(float, t, x + redux); |
119 GET_FLOAT_WORD(i0, t); 120 i0 += TBLSIZE / 2; 121 k = (i0 >> TBLBITS) << 23; 122 i0 &= TBLSIZE - 1; 123 t -= redux; 124 z = x - t; 125 126 /* Compute r = exp2(y) = exp2ft[i0] * p(z). */ --- 16 unchanged lines hidden --- | 120 GET_FLOAT_WORD(i0, t); 121 i0 += TBLSIZE / 2; 122 k = (i0 >> TBLBITS) << 23; 123 i0 &= TBLSIZE - 1; 124 t -= redux; 125 z = x - t; 126 127 /* Compute r = exp2(y) = exp2ft[i0] * p(z). */ --- 16 unchanged lines hidden --- |