]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/msun/src/k_logf.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / lib / msun / src / k_logf.h
1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
5  * Developed at SunPro, a Sun Microsystems, Inc. business.
6  * Permission to use, copy, modify, and distribute this
7  * software is freely granted, provided that this notice
8  * is preserved.
9  * ====================================================
10  */
11
12 #include <sys/cdefs.h>
13 __FBSDID("$FreeBSD$");
14
15 /*
16  * float version of __kernel_log(x). See k_log.c for details.
17  */
18
19 static const float
20 /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
21 Lg1 =      0xaaaaaa.0p-24,      /* 0.66666662693 */
22 Lg2 =      0xccce13.0p-25,      /* 0.40000972152 */
23 Lg3 =      0x91e9ee.0p-25,      /* 0.28498786688 */
24 Lg4 =      0xf89e26.0p-26;      /* 0.24279078841 */
25
26 static inline float
27 __kernel_logf(float x)
28 {
29         float hfsq,f,s,z,R,w,t1,t2;
30         int32_t ix,i,j;
31
32         GET_FLOAT_WORD(ix,x);
33
34         f = x-(float)1.0;
35         if((0x007fffff&(0x8000+ix))<0xc000) {   /* -2**-9 <= f < 2**-9 */
36             if(f==0.0f) return 0.0f;
37             return f*f*((float)0.33333333333333333*f-(float)0.5);
38         }
39         s = f/((float)2.0+f);
40         z = s*s;
41         ix &= 0x007fffff;
42         i = ix-(0x6147a<<3);
43         w = z*z;
44         j = (0x6b851<<3)-ix;
45         t1= w*(Lg2+w*Lg4);
46         t2= z*(Lg1+w*Lg3);
47         i |= j;
48         R = t2+t1;
49         if(i>0) {
50             hfsq=(float)0.5*f*f;
51             return s*(hfsq+R) - hfsq;
52         } else {
53             return s*(R-f);
54         }
55 }