1*05a0b428SJohn Marino /* s_cbrtf.c -- float version of s_cbrt.c.
2*05a0b428SJohn Marino * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3*05a0b428SJohn Marino */
4*05a0b428SJohn Marino
5*05a0b428SJohn Marino /*
6*05a0b428SJohn Marino * ====================================================
7*05a0b428SJohn Marino * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8*05a0b428SJohn Marino *
9*05a0b428SJohn Marino * Developed at SunPro, a Sun Microsystems, Inc. business.
10*05a0b428SJohn Marino * Permission to use, copy, modify, and distribute this
11*05a0b428SJohn Marino * software is freely granted, provided that this notice
12*05a0b428SJohn Marino * is preserved.
13*05a0b428SJohn Marino * ====================================================
14*05a0b428SJohn Marino */
15*05a0b428SJohn Marino
16*05a0b428SJohn Marino #include "math.h"
17*05a0b428SJohn Marino #include "math_private.h"
18*05a0b428SJohn Marino
19*05a0b428SJohn Marino /* cbrtf(x)
20*05a0b428SJohn Marino * Return cube root of x
21*05a0b428SJohn Marino */
22*05a0b428SJohn Marino static const unsigned
23*05a0b428SJohn Marino B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
24*05a0b428SJohn Marino B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
25*05a0b428SJohn Marino
26*05a0b428SJohn Marino static const float
27*05a0b428SJohn Marino C = 5.4285717010e-01, /* 19/35 = 0x3f0af8b0 */
28*05a0b428SJohn Marino D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
29*05a0b428SJohn Marino E = 1.4142856598e+00, /* 99/70 = 0x3fb50750 */
30*05a0b428SJohn Marino F = 1.6071428061e+00, /* 45/28 = 0x3fcdb6db */
31*05a0b428SJohn Marino G = 3.5714286566e-01; /* 5/14 = 0x3eb6db6e */
32*05a0b428SJohn Marino
33*05a0b428SJohn Marino float
cbrtf(float x)34*05a0b428SJohn Marino cbrtf(float x)
35*05a0b428SJohn Marino {
36*05a0b428SJohn Marino float r,s,t;
37*05a0b428SJohn Marino int32_t hx;
38*05a0b428SJohn Marino u_int32_t sign;
39*05a0b428SJohn Marino u_int32_t high;
40*05a0b428SJohn Marino
41*05a0b428SJohn Marino GET_FLOAT_WORD(hx,x);
42*05a0b428SJohn Marino sign=hx&0x80000000; /* sign= sign(x) */
43*05a0b428SJohn Marino hx ^=sign;
44*05a0b428SJohn Marino if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
45*05a0b428SJohn Marino if(hx==0)
46*05a0b428SJohn Marino return(x); /* cbrt(0) is itself */
47*05a0b428SJohn Marino
48*05a0b428SJohn Marino SET_FLOAT_WORD(x,hx); /* x <- |x| */
49*05a0b428SJohn Marino /* rough cbrt to 5 bits */
50*05a0b428SJohn Marino if(hx<0x00800000) /* subnormal number */
51*05a0b428SJohn Marino {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
52*05a0b428SJohn Marino t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
53*05a0b428SJohn Marino }
54*05a0b428SJohn Marino else
55*05a0b428SJohn Marino SET_FLOAT_WORD(t,hx/3+B1);
56*05a0b428SJohn Marino
57*05a0b428SJohn Marino
58*05a0b428SJohn Marino /* new cbrt to 23 bits */
59*05a0b428SJohn Marino r=t*t/x;
60*05a0b428SJohn Marino s=C+r*t;
61*05a0b428SJohn Marino t*=G+F/(s+E+D/s);
62*05a0b428SJohn Marino
63*05a0b428SJohn Marino /* retore the sign bit */
64*05a0b428SJohn Marino GET_FLOAT_WORD(high,t);
65*05a0b428SJohn Marino SET_FLOAT_WORD(t,high|sign);
66*05a0b428SJohn Marino return(t);
67*05a0b428SJohn Marino }
68