add packages_10.03.2 in preparation for the 10.03.2 interim release
[10.03/packages.git] / utils / ipmitool / patches / 100-cubic_root.patch
1 --- a/lib/ipmi_sdr.c
2 +++ b/lib/ipmi_sdr.c
3 @@ -4399,3 +4399,146 @@ ipmi_sdr_main(struct ipmi_intf *intf, in
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 +/*
63 +double frexp(), ldexp();
64 +int isnan(double), isfinite(double);
65 +*/
66 +#endif
67 +
68 +double cbrt(double x)
69 +{
70 +/* double x; */
71 +int e, rem, sign;
72 +double z;
73 +
74 +#ifdef NANS
75 +if( isnan(x) )
76 +  return x;
77 +#endif
78 +#ifdef INFINITIES
79 +if( !isfinite(x) )
80 +  return x;
81 +#endif
82 +if( x == 0 )
83 +       return( x );
84 +if( x > 0 )
85 +       sign = 1;
86 +else
87 +       {
88 +       sign = -1;
89 +       x = -x;
90 +       }
91 +
92 +z = x;
93 +/* extract power of 2, leaving
94 + * mantissa between 0.5 and 1
95 + */
96 +x = frexp( x, &e );
97 +
98 +/* Approximate cube root of number between .5 and 1,
99 + * peak relative error = 9.2e-6
100 + */
101 +x = (((-1.3466110473359520655053e-1  * x
102 +      + 5.4664601366395524503440e-1) * x
103 +      - 9.5438224771509446525043e-1) * x
104 +      + 1.1399983354717293273738e0 ) * x
105 +      + 4.0238979564544752126924e-1;
106 +
107 +/* exponent divided by 3 */
108 +if( e >= 0 )
109 +       {
110 +       rem = e;
111 +       e /= 3;
112 +       rem -= 3*e;
113 +       if( rem == 1 )
114 +               x *= CBRT2;
115 +       else if( rem == 2 )
116 +               x *= CBRT4;
117 +       }
118 +
119 +
120 +/* argument less than 1 */
121 +
122 +else
123 +       {
124 +       e = -e;
125 +       rem = e;
126 +       e /= 3;
127 +       rem -= 3*e;
128 +       if( rem == 1 )
129 +               x *= CBRT2I;
130 +       else if( rem == 2 )
131 +               x *= CBRT4I;
132 +       e = -e;
133 +       }
134 +
135 +/* multiply by power of 2 */
136 +x = ldexp( x, e );
137 +
138 +/* Newton iteration */
139 +x -= ( x - (z/(x*x)) )*0.33333333333333333333;
140 +#ifdef DEC
141 +x -= ( x - (z/(x*x)) )/3.0;
142 +#else
143 +x -= ( x - (z/(x*x)) )*0.33333333333333333333;
144 +#endif
145 +
146 +if( sign < 0 )
147 +       x = -x;
148 +return(x);
149 +}