Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / common / sf_log1p.c
blobd326e00bad063c3e406849c35176ac440c186a56
1 /* sf_log1p.c -- float version of s_log1p.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
16 #include "fdlibm.h"
17 #include "math_config.h"
19 #ifdef __STDC__
20 static const float
21 #else
22 static float
23 #endif
24 ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
25 ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
26 two25 = 3.355443200e+07, /* 0x4c000000 */
27 Lp1 = 6.6666668653e-01, /* 3F2AAAAB */
28 Lp2 = 4.0000000596e-01, /* 3ECCCCCD */
29 Lp3 = 2.8571429849e-01, /* 3E924925 */
30 Lp4 = 2.2222198546e-01, /* 3E638E29 */
31 Lp5 = 1.8183572590e-01, /* 3E3A3325 */
32 Lp6 = 1.5313838422e-01, /* 3E1CD04F */
33 Lp7 = 1.4798198640e-01; /* 3E178897 */
35 #ifdef __STDC__
36 static const float zero = 0.0;
37 #else
38 static float zero = 0.0;
39 #endif
41 #ifdef __STDC__
42 float log1pf(float x)
43 #else
44 float log1pf(x)
45 float x;
46 #endif
48 float hfsq,f,c,s,z,R,u;
49 __int32_t k,hx,hu,ax;
51 GET_FLOAT_WORD(hx,x);
52 ax = hx&0x7fffffff;
54 k = 1;
55 if (!FLT_UWORD_IS_FINITE(hx)) return x+x;
56 if (hx < 0x3ed413d7) { /* x < 0.41422 */
57 if(ax>=0x3f800000) { /* x <= -1.0 */
58 if(x==(float)-1.0)
59 return __math_divzerof (1); /* log1p(-1)=-inf */
60 else
61 return __math_invalidf (x); /* log1p(x<-1)=NaN */
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;
70 if(hx>0||hx<=((__int32_t)0xbe95f61f)) {
71 k=0;f=x;hu=1;} /* -0.2929<x<0.41422 */
73 if(k!=0) {
74 if(hx<0x5a000000) {
75 u = (float)1.0+x;
76 GET_FLOAT_WORD(hu,u);
77 k = (hu>>23)-127;
78 /* correction term */
79 c = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0);
80 c /= u;
81 } else {
82 u = x;
83 GET_FLOAT_WORD(hu,u);
84 k = (hu>>23)-127;
85 c = 0;
87 hu &= 0x007fffff;
88 if(hu<0x3504f7) {
89 SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */
90 } else {
91 k += 1;
92 SET_FLOAT_WORD(u,hu|0x3f000000); /* normalize u/2 */
93 hu = (0x00800000-hu)>>2;
95 f = u-(float)1.0;
97 hfsq=(float)0.5*f*f;
98 if(hu==0) { /* |f| < 2**-20 */
99 if(f==zero) { if(k==0) return zero;
100 else {c += k*ln2_lo; return k*ln2_hi+c;}}
101 R = hfsq*((float)1.0-(float)0.66666666666666666*f);
102 if(k==0) return f-R; else
103 return k*ln2_hi-((R-(k*ln2_lo+c))-f);
105 s = f/((float)2.0+f);
106 z = s*s;
107 R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
108 if(k==0) return f-(hfsq-s*(hfsq+R)); else
109 return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
112 #ifdef _DOUBLE_IS_32BITS
114 #ifdef __STDC__
115 double log1p(double x)
116 #else
117 double log1p(x)
118 double x;
119 #endif
121 return (double) log1pf((float) x);
124 #endif /* defined(_DOUBLE_IS_32BITS) */