ipiq: Add simple IPI latency measure sysctls (2)
[dragonfly.git] / lib / libm / src / s_log1pf.c
CommitLineData
b34b60bc
JS
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
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
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 * ====================================================
6ff43c94 14 * $FreeBSD: head/lib/msun/src/s_log1pf.c 251024 2013-05-27 08:50:10Z das $
b34b60bc
JS
15 */
16
6ff43c94
PA
17#include <float.h>
18
19#include "math.h"
b34b60bc
JS
20#include "math_private.h"
21
22static const float
23ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
24ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
25two25 = 3.355443200e+07, /* 0x4c000000 */
26Lp1 = 6.6666668653e-01, /* 3F2AAAAB */
27Lp2 = 4.0000000596e-01, /* 3ECCCCCD */
28Lp3 = 2.8571429849e-01, /* 3E924925 */
29Lp4 = 2.2222198546e-01, /* 3E638E29 */
30Lp5 = 1.8183572590e-01, /* 3E3A3325 */
31Lp6 = 1.5313838422e-01, /* 3E1CD04F */
32Lp7 = 1.4798198640e-01; /* 3E178897 */
33
34static const float zero = 0.0;
6ff43c94 35static volatile float vzero = 0.0;
b34b60bc
JS
36
37float
38log1pf(float x)
39{
40 float hfsq,f,c,s,z,R,u;
41 int32_t k,hx,hu,ax;
42
b34b60bc
JS
43 GET_FLOAT_WORD(hx,x);
44 ax = hx&0x7fffffff;
45
46 k = 1;
6ff43c94 47 if (hx < 0x3ed413d0) { /* 1+x < sqrt(2)+ */
b34b60bc 48 if(ax>=0x3f800000) { /* x <= -1.0 */
6ff43c94 49 if(x==(float)-1.0) return -two25/vzero; /* log1p(-1)=+inf */
b34b60bc
JS
50 else return (x-x)/(x-x); /* log1p(x<-1)=NaN */
51 }
6ff43c94 52 if(ax<0x38000000) { /* |x| < 2**-15 */
b34b60bc 53 if(two25+x>zero /* raise inexact */
6ff43c94 54 &&ax<0x33800000) /* |x| < 2**-24 */
b34b60bc
JS
55 return x;
56 else
57 return x - x*x*(float)0.5;
58 }
6ff43c94
PA
59 if(hx>0||hx<=((int32_t)0xbe95f619)) {
60 k=0;f=x;hu=1;} /* sqrt(2)/2- <= 1+x < sqrt(2)+ */
b34b60bc
JS
61 }
62 if (hx >= 0x7f800000) return x+x;
63 if(k!=0) {
64 if(hx<0x5a000000) {
6ff43c94 65 STRICT_ASSIGN(float,u,(float)1.0+x);
b34b60bc
JS
66 GET_FLOAT_WORD(hu,u);
67 k = (hu>>23)-127;
68 /* correction term */
69 c = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0);
70 c /= u;
71 } else {
72 u = x;
73 GET_FLOAT_WORD(hu,u);
74 k = (hu>>23)-127;
75 c = 0;
76 }
77 hu &= 0x007fffff;
6ff43c94
PA
78 /*
79 * The approximation to sqrt(2) used in thresholds is not
80 * critical. However, the ones used above must give less
81 * strict bounds than the one here so that the k==0 case is
82 * never reached from here, since here we have committed to
83 * using the correction term but don't use it if k==0.
84 */
85 if(hu<0x3504f4) { /* u < sqrt(2) */
b34b60bc
JS
86 SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */
87 } else {
88 k += 1;
89 SET_FLOAT_WORD(u,hu|0x3f000000); /* normalize u/2 */
90 hu = (0x00800000-hu)>>2;
91 }
92 f = u-(float)1.0;
93 }
94 hfsq=(float)0.5*f*f;
95 if(hu==0) { /* |f| < 2**-20 */
6ff43c94
PA
96 if(f==zero) {
97 if(k==0) {
98 return zero;
99 } else {
100 c += k*ln2_lo;
101 return k*ln2_hi+c;
102 }
b34b60bc
JS
103 }
104 R = hfsq*((float)1.0-(float)0.66666666666666666*f);
105 if(k==0) return f-R; else
106 return k*ln2_hi-((R-(k*ln2_lo+c))-f);
107 }
108 s = f/((float)2.0+f);
109 z = s*s;
110 R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
111 if(k==0) return f-(hfsq-s*(hfsq+R)); else
112 return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
113}