d061e5f1af0e4f2d3a91f654b1f5d98772f7bbc9
[openwrt/svn-archive/archive.git] / utils / ipmitool / patches / 100-cubic_root.patch
1 --- ipmitool-1.8.9/lib/ipmi_sdr.c.orig 2007-07-16 13:09:13.000000000 +0200
2 +++ ipmitool-1.8.9/lib/ipmi_sdr.c 2007-07-16 13:09:20.000000000 +0200
3 @@ -4264,3 +4264,144 @@
4
5 return rc;
6 }
7 +
8 +/* cbrt.c
9 + *
10 + * Cube root
11 + *
12 + *
13 + *
14 + * SYNOPSIS:
15 + *
16 + * double x, y, cbrt();
17 + *
18 + * y = cbrt( x );
19 + *
20 + *
21 + *
22 + * DESCRIPTION:
23 + *
24 + * Returns the cube root of the argument, which may be negative.
25 + *
26 + * Range reduction involves determining the power of 2 of
27 + * the argument. A polynomial of degree 2 applied to the
28 + * mantissa, and multiplication by the cube root of 1, 2, or 4
29 + * approximates the root to within about 0.1%. Then Newton's
30 + * iteration is used three times to converge to an accurate
31 + * result.
32 + *
33 + *
34 + *
35 + * ACCURACY:
36 + *
37 + * Relative error:
38 + * arithmetic domain # trials peak rms
39 + * DEC -10,10 200000 1.8e-17 6.2e-18
40 + * IEEE 0,1e308 30000 1.5e-16 5.0e-17
41 + *
42 + */
43 +/* cbrt.c */
44 +
45 +/*
46 +Cephes Math Library Release 2.8: June, 2000
47 +Copyright 1984, 1991, 2000 by Stephen L. Moshier
48 +*/
49 +
50 +
51 +static double CBRT2 = 1.2599210498948731647672;
52 +static double CBRT4 = 1.5874010519681994747517;
53 +static double CBRT2I = 0.79370052598409973737585;
54 +static double CBRT4I = 0.62996052494743658238361;
55 +
56 +#ifdef ANSIPROT
57 +extern double frexp ( double, int * );
58 +extern double ldexp ( double, int );
59 +extern int isnan ( double );
60 +extern int isfinite ( double );
61 +#else
62 +double frexp(), ldexp();
63 +int isnan(), isfinite();
64 +#endif
65 +
66 +double cbrt(x)
67 +double x;
68 +{
69 +int e, rem, sign;
70 +double z;
71 +
72 +#ifdef NANS
73 +if( isnan(x) )
74 + return x;
75 +#endif
76 +#ifdef INFINITIES
77 +if( !isfinite(x) )
78 + return x;
79 +#endif
80 +if( x == 0 )
81 + return( x );
82 +if( x > 0 )
83 + sign = 1;
84 +else
85 + {
86 + sign = -1;
87 + x = -x;
88 + }
89 +
90 +z = x;
91 +/* extract power of 2, leaving
92 + * mantissa between 0.5 and 1
93 + */
94 +x = frexp( x, &e );
95 +
96 +/* Approximate cube root of number between .5 and 1,
97 + * peak relative error = 9.2e-6
98 + */
99 +x = (((-1.3466110473359520655053e-1 * x
100 + + 5.4664601366395524503440e-1) * x
101 + - 9.5438224771509446525043e-1) * x
102 + + 1.1399983354717293273738e0 ) * x
103 + + 4.0238979564544752126924e-1;
104 +
105 +/* exponent divided by 3 */
106 +if( e >= 0 )
107 + {
108 + rem = e;
109 + e /= 3;
110 + rem -= 3*e;
111 + if( rem == 1 )
112 + x *= CBRT2;
113 + else if( rem == 2 )
114 + x *= CBRT4;
115 + }
116 +
117 +
118 +/* argument less than 1 */
119 +
120 +else
121 + {
122 + e = -e;
123 + rem = e;
124 + e /= 3;
125 + rem -= 3*e;
126 + if( rem == 1 )
127 + x *= CBRT2I;
128 + else if( rem == 2 )
129 + x *= CBRT4I;
130 + e = -e;
131 + }
132 +
133 +/* multiply by power of 2 */
134 +x = ldexp( x, e );
135 +
136 +/* Newton iteration */
137 +x -= ( x - (z/(x*x)) )*0.33333333333333333333;
138 +#ifdef DEC
139 +x -= ( x - (z/(x*x)) )/3.0;
140 +#else
141 +x -= ( x - (z/(x*x)) )*0.33333333333333333333;
142 +#endif
143 +
144 +if( sign < 0 )
145 + x = -x;
146 +return(x);
147 +}