Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / msun / src / s_log1pf.c
1 /* s_log1pf.c -- float version of s_log1p.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  *
4  * $FreeBSD: src/lib/msun/src/s_log1pf.c,v 1.5 1999/08/28 00:06:52 peter Exp $
5  * $DragonFly: src/lib/msun/src/Attic/s_log1pf.c,v 1.2 2003/06/17 04:26:53 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 ln2_hi =   6.9313812256e-01,    /* 0x3f317180 */
28 ln2_lo =   9.0580006145e-06,    /* 0x3717f7d1 */
29 two25 =    3.355443200e+07,     /* 0x4c000000 */
30 Lp1 = 6.6666668653e-01, /* 3F2AAAAB */
31 Lp2 = 4.0000000596e-01, /* 3ECCCCCD */
32 Lp3 = 2.8571429849e-01, /* 3E924925 */
33 Lp4 = 2.2222198546e-01, /* 3E638E29 */
34 Lp5 = 1.8183572590e-01, /* 3E3A3325 */
35 Lp6 = 1.5313838422e-01, /* 3E1CD04F */
36 Lp7 = 1.4798198640e-01; /* 3E178897 */
37
38 #ifdef __STDC__
39 static const float zero = 0.0;
40 #else
41 static float zero = 0.0;
42 #endif
43
44 #ifdef __STDC__
45         float log1pf(float x)
46 #else
47         float log1pf(x)
48         float x;
49 #endif
50 {
51         float hfsq,f,c,s,z,R,u;
52         int32_t k,hx,hu,ax;
53
54         GET_FLOAT_WORD(hx,x);
55         ax = hx&0x7fffffff;
56
57         k = 1;
58         if (hx < 0x3ed413d7) {                  /* x < 0.41422  */
59             if(ax>=0x3f800000) {                /* x <= -1.0 */
60                 if(x==(float)-1.0) return -two25/zero; /* log1p(-1)=+inf */
61                 else return (x-x)/(x-x);        /* log1p(x<-1)=NaN */
62             }
63             if(ax<0x31000000) {                 /* |x| < 2**-29 */
64                 if(two25+x>zero                 /* raise inexact */
65                     &&ax<0x24800000)            /* |x| < 2**-54 */
66                     return x;
67                 else
68                     return x - x*x*(float)0.5;
69             }
70             if(hx>0||hx<=((int32_t)0xbe95f61f)) {
71                 k=0;f=x;hu=1;}  /* -0.2929<x<0.41422 */
72         }
73         if (hx >= 0x7f800000) return x+x;
74         if(k!=0) {
75             if(hx<0x5a000000) {
76                 u  = (float)1.0+x;
77                 GET_FLOAT_WORD(hu,u);
78                 k  = (hu>>23)-127;
79                 /* correction term */
80                 c  = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0);
81                 c /= u;
82             } else {
83                 u  = x;
84                 GET_FLOAT_WORD(hu,u);
85                 k  = (hu>>23)-127;
86                 c  = 0;
87             }
88             hu &= 0x007fffff;
89             if(hu<0x3504f7) {
90                 SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */
91             } else {
92                 k += 1;
93                 SET_FLOAT_WORD(u,hu|0x3f000000);        /* normalize u/2 */
94                 hu = (0x00800000-hu)>>2;
95             }
96             f = u-(float)1.0;
97         }
98         hfsq=(float)0.5*f*f;
99         if(hu==0) {     /* |f| < 2**-20 */
100             if(f==zero) if(k==0) return zero;
101                         else {c += k*ln2_lo; return k*ln2_hi+c;}
102             R = hfsq*((float)1.0-(float)0.66666666666666666*f);
103             if(k==0) return f-R; else
104                      return k*ln2_hi-((R-(k*ln2_lo+c))-f);
105         }
106         s = f/((float)2.0+f);
107         z = s*s;
108         R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
109         if(k==0) return f-(hfsq-s*(hfsq+R)); else
110                  return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
111 }