1 /* s_cbrtf.c -- float version of s_cbrt.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  * ====================================================
14  */
15 
16 #include "math.h"
17 #include "math_private.h"
18 
19 /* cbrtf(x)
20  * Return cube root of x
21  */
22 static const unsigned
23 B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
24 B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
25 
26 static const float
27 C =  5.4285717010e-01, /* 19/35     = 0x3f0af8b0 */
28 D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
29 E =  1.4142856598e+00, /* 99/70     = 0x3fb50750 */
30 F =  1.6071428061e+00, /* 45/28     = 0x3fcdb6db */
31 G =  3.5714286566e-01; /* 5/14      = 0x3eb6db6e */
32 
33 float
34 cbrtf(float x)
35 {
36 	float r,s,t;
37 	int32_t hx;
38 	u_int32_t sign;
39 	u_int32_t high;
40 
41 	GET_FLOAT_WORD(hx,x);
42 	sign=hx&0x80000000; 		/* sign= sign(x) */
43 	hx  ^=sign;
44 	if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
45 	if(hx==0)
46 	    return(x);		/* cbrt(0) is itself */
47 
48 	SET_FLOAT_WORD(x,hx);	/* x <- |x| */
49     /* rough cbrt to 5 bits */
50 	if(hx<0x00800000) 		/* subnormal number */
51 	  {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
52 	   t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
53 	  }
54 	else
55 	  SET_FLOAT_WORD(t,hx/3+B1);
56 
57 
58     /* new cbrt to 23 bits */
59 	r=t*t/x;
60 	s=C+r*t;
61 	t*=G+F/(s+E+D/s);
62 
63     /* retore the sign bit */
64 	GET_FLOAT_WORD(high,t);
65 	SET_FLOAT_WORD(t,high|sign);
66 	return(t);
67 }
68