2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / flt-32 / s_log1pf.c
blobbd3d57635c5844afb0c899863bb58436702d95f1
1 /* s_log1pf.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 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: s_log1pf.c,v 1.4 1995/05/10 20:47:48 jtc Exp $";
18 #endif
20 #include "math.h"
21 #include "math_private.h"
23 #ifdef __STDC__
24 static const float
25 #else
26 static float
27 #endif
28 ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
29 ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
30 two25 = 3.355443200e+07, /* 0x4c000000 */
31 Lp1 = 6.6666668653e-01, /* 3F2AAAAB */
32 Lp2 = 4.0000000596e-01, /* 3ECCCCCD */
33 Lp3 = 2.8571429849e-01, /* 3E924925 */
34 Lp4 = 2.2222198546e-01, /* 3E638E29 */
35 Lp5 = 1.8183572590e-01, /* 3E3A3325 */
36 Lp6 = 1.5313838422e-01, /* 3E1CD04F */
37 Lp7 = 1.4798198640e-01; /* 3E178897 */
39 #ifdef __STDC__
40 static const float zero = 0.0;
41 #else
42 static float zero = 0.0;
43 #endif
45 #ifdef __STDC__
46 float __log1pf(float x)
47 #else
48 float __log1pf(x)
49 float x;
50 #endif
52 float hfsq,f,c,s,z,R,u;
53 int32_t k,hx,hu,ax;
55 GET_FLOAT_WORD(hx,x);
56 ax = hx&0x7fffffff;
58 k = 1;
59 if (hx < 0x3ed413d7) { /* x < 0.41422 */
60 if(ax>=0x3f800000) { /* x <= -1.0 */
61 if(x==(float)-1.0) return -two25/(x-x); /* log1p(-1)=+inf */
62 else return (x-x)/(x-x); /* log1p(x<-1)=NaN */
64 if(ax<0x31000000) { /* |x| < 2**-29 */
65 if(two25+x>zero /* raise inexact */
66 &&ax<0x24800000) /* |x| < 2**-54 */
67 return x;
68 else
69 return x - x*x*(float)0.5;
71 if(hx>0||hx<=((int32_t)0xbe95f61f)) {
72 k=0;f=x;hu=1;} /* -0.2929<x<0.41422 */
74 if (hx >= 0x7f800000) return x+x;
75 if(k!=0) {
76 if(hx<0x5a000000) {
77 u = (float)1.0+x;
78 GET_FLOAT_WORD(hu,u);
79 k = (hu>>23)-127;
80 /* correction term */
81 c = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0);
82 c /= u;
83 } else {
84 u = x;
85 GET_FLOAT_WORD(hu,u);
86 k = (hu>>23)-127;
87 c = 0;
89 hu &= 0x007fffff;
90 if(hu<0x3504f7) {
91 SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */
92 } else {
93 k += 1;
94 SET_FLOAT_WORD(u,hu|0x3f000000); /* normalize u/2 */
95 hu = (0x00800000-hu)>>2;
97 f = u-(float)1.0;
99 hfsq=(float)0.5*f*f;
100 if(hu==0) { /* |f| < 2**-20 */
101 if(f==zero) {
102 if(k==0) return zero;
103 else {c += k*ln2_lo; return k*ln2_hi+c;}
105 R = hfsq*((float)1.0-(float)0.66666666666666666*f);
106 if(k==0) return f-R; else
107 return k*ln2_hi-((R-(k*ln2_lo+c))-f);
109 s = f/((float)2.0+f);
110 z = s*s;
111 R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
112 if(k==0) return f-(hfsq-s*(hfsq+R)); else
113 return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
115 weak_alias (__log1pf, log1pf)