1:
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: #include <sys/cdefs.h>
16: #include <float.h>
17: #include <math.h>
18:
19: #include "math_private.h"
20:
21: 22: 23:
24: static const u_int32_t
25: B1 = 715094163,
26: B2 = 696219795;
27:
28: static const double
29: C = 5.42857142857142815906e-01,
30: D = -7.05306122448979611050e-01,
31: E = 1.41428571428571436819e+00,
32: F = 1.60714285714285720630e+00,
33: G = 3.57142857142857150787e-01;
34:
35: double
36: cbrt(double x)
37: {
38: int32_t hx;
39: double r,s,t=0.0,w;
40: u_int32_t sign;
41: u_int32_t high,low;
42:
43: GET_HIGH_WORD(hx,x);
44: sign=hx&0x80000000;
45: hx ^=sign;
46: if(hx>=0x7ff00000) return(x+x);
47: GET_LOW_WORD(low,x);
48: if((hx|low)==0)
49: return(x);
50:
51: SET_HIGH_WORD(x,hx);
52:
53: if(hx<0x00100000)
54: {SET_HIGH_WORD(t,0x43500000);
55: t*=x; GET_HIGH_WORD(high,t); SET_HIGH_WORD(t,high/3+B2);
56: }
57: else
58: SET_HIGH_WORD(t,hx/3+B1);
59:
60:
61:
62: r=t*t/x;
63: s=C+r*t;
64: t*=G+F/(s+E+D/s);
65:
66:
67: GET_HIGH_WORD(high,t);
68: INSERT_WORDS(t,high+0x00000001,0);
69:
70:
71:
72: s=t*t;
73: r=x/s;
74: w=t+t;
75: r=(r-t)/(w+r);
76: t=t+t*r;
77:
78:
79: GET_HIGH_WORD(high,t);
80: SET_HIGH_WORD(t,high|sign);
81: return(t);
82: }
83:
84: #if LDBL_MANT_DIG == 53
85: #ifdef lint
86:
87: long double cbrtl(long double);
88: #else
89: __weak_alias(cbrtl, cbrt);
90: #endif
91: #endif