Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / msun / src / e_expf.c
1 /* e_expf.c -- float version of e_exp.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  *
4  * $FreeBSD: src/lib/msun/src/e_expf.c,v 1.6 1999/08/28 00:06:30 peter Exp $
5  * $DragonFly: src/lib/msun/src/Attic/e_expf.c,v 1.2 2003/06/17 04:26:52 dillon Exp $
6  */
7
8 /*
9  * ====================================================
10  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11  *
12  * Developed at SunPro, a Sun Microsystems, Inc. business.
13  * Permission to use, copy, modify, and distribute this
14  * software is freely granted, provided that this notice
15  * is preserved.
16  * ====================================================
17  */
18
19 #include "math.h"
20 #include "math_private.h"
21
22 #ifdef __STDC__
23 static const float
24 #else
25 static float
26 #endif
27 one     = 1.0,
28 halF[2] = {0.5,-0.5,},
29 huge    = 1.0e+30,
30 twom100 = 7.8886090522e-31,      /* 2**-100=0x0d800000 */
31 o_threshold=  8.8721679688e+01,  /* 0x42b17180 */
32 u_threshold= -1.0397208405e+02,  /* 0xc2cff1b5 */
33 ln2HI[2]   ={ 6.9313812256e-01,         /* 0x3f317180 */
34              -6.9313812256e-01,},       /* 0xbf317180 */
35 ln2LO[2]   ={ 9.0580006145e-06,         /* 0x3717f7d1 */
36              -9.0580006145e-06,},       /* 0xb717f7d1 */
37 invln2 =  1.4426950216e+00,             /* 0x3fb8aa3b */
38 P1   =  1.6666667163e-01, /* 0x3e2aaaab */
39 P2   = -2.7777778450e-03, /* 0xbb360b61 */
40 P3   =  6.6137559770e-05, /* 0x388ab355 */
41 P4   = -1.6533901999e-06, /* 0xb5ddea0e */
42 P5   =  4.1381369442e-08; /* 0x3331bb4c */
43
44 #ifdef __STDC__
45         float __ieee754_expf(float x)   /* default IEEE double exp */
46 #else
47         float __ieee754_expf(x) /* default IEEE double exp */
48         float x;
49 #endif
50 {
51         float y,hi=0.0,lo=0.0,c,t;
52         int32_t k=0,xsb;
53         u_int32_t hx;
54
55         GET_FLOAT_WORD(hx,x);
56         xsb = (hx>>31)&1;               /* sign bit of x */
57         hx &= 0x7fffffff;               /* high word of |x| */
58
59     /* filter out non-finite argument */
60         if(hx >= 0x42b17218) {                  /* if |x|>=88.721... */
61             if(hx>0x7f800000)
62                  return x+x;                    /* NaN */
63             if(hx==0x7f800000)
64                 return (xsb==0)? x:0.0;         /* exp(+-inf)={inf,0} */
65             if(x > o_threshold) return huge*huge; /* overflow */
66             if(x < u_threshold) return twom100*twom100; /* underflow */
67         }
68
69     /* argument reduction */
70         if(hx > 0x3eb17218) {           /* if  |x| > 0.5 ln2 */
71             if(hx < 0x3F851592) {       /* and |x| < 1.5 ln2 */
72                 hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
73             } else {
74                 k  = invln2*x+halF[xsb];
75                 t  = k;
76                 hi = x - t*ln2HI[0];    /* t*ln2HI is exact here */
77                 lo = t*ln2LO[0];
78             }
79             x  = hi - lo;
80         }
81         else if(hx < 0x31800000)  {     /* when |x|<2**-28 */
82             if(huge+x>one) return one+x;/* trigger inexact */
83         }
84         else k = 0;
85
86     /* x is now in primary range */
87         t  = x*x;
88         c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
89         if(k==0)        return one-((x*c)/(c-(float)2.0)-x);
90         else            y = one-((lo-(x*c)/((float)2.0-c))-hi);
91         if(k >= -125) {
92             u_int32_t hy;
93             GET_FLOAT_WORD(hy,y);
94             SET_FLOAT_WORD(y,hy+(k<<23));       /* add k to y's exponent */
95             return y;
96         } else {
97             u_int32_t hy;
98             GET_FLOAT_WORD(hy,y);
99             SET_FLOAT_WORD(y,hy+((k+100)<<23)); /* add k to y's exponent */
100             return y*twom100;
101         }
102 }