1 /* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtf.c */
3 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
4 * 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 * Return cube root of x
24 B1
= 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */
25 B2
= 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
30 union {float f
; uint32_t i
;} u
= {x
};
31 uint32_t hx
= u
.i
& 0x7fffffff;
33 if (hx
>= 0x7f800000) /* cbrt(NaN,INF) is itself */
36 /* rough cbrt to 5 bits */
37 if (hx
< 0x00800000) { /* zero or subnormal? */
39 return x
; /* cbrt(+-0) is itself */
41 hx
= u
.i
& 0x7fffffff;
49 * First step Newton iteration (solving t*t-x/t == 0) to 16 bits. In
50 * double precision so that its terms can be arranged for efficiency
51 * without causing overflow or underflow.
55 T
= T
*((double_t
)x
+x
+r
)/(x
+r
+r
);
58 * Second step Newton iteration to 47 bits. In double precision for
59 * efficiency and accuracy.
62 T
= T
*((double_t
)x
+x
+r
)/(x
+r
+r
);
64 /* rounding to 24 bits is perfect in round-to-nearest mode */