1 /* s_cbrtf.c -- float version of s_cbrt.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 * Debugged and optimized by Bruce D. Evans.
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
14 * ====================================================
17 #include <sys/cdefs.h>
18 __FBSDID("$FreeBSD$");
21 #include "math_private.h"
24 * Return cube root of x
27 B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */
28 B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
40 sign=hx&0x80000000; /* sign= sign(x) */
42 if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
44 /* rough cbrt to 5 bits */
45 if(hx<0x00800000) { /* zero or subnormal? */
47 return(x); /* cbrt(+-0) is itself */
48 SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
50 GET_FLOAT_WORD(high,t);
51 SET_FLOAT_WORD(t,sign|((high&0x7fffffff)/3+B2));
53 SET_FLOAT_WORD(t,sign|(hx/3+B1));
56 * First step Newton iteration (solving t*t-x/t == 0) to 16 bits. In
57 * double precision so that its terms can be arranged for efficiency
58 * without causing overflow or underflow.
62 T=T*((double)x+x+r)/(x+r+r);
65 * Second step Newton iteration to 47 bits. In double precision for
66 * efficiency and accuracy.
69 T=T*((double)x+x+r)/(x+r+r);
71 /* rounding to 24 bits is perfect in round-to-nearest mode */