Wed Jul 17 21:53:45 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / sysdeps / libm-ieee754 / s_cbrtf.c
bloba2b3c8106c98c5f821e68d78c5d7969b63b7c862
1 /* s_cbrtf.c -- float version of s_cbrt.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: s_cbrtf.c,v 1.4 1995/05/10 20:46:51 jtc Exp $";
18 #endif
20 #include "math.h"
21 #include "math_private.h"
23 /* cbrtf(x)
24 * Return cube root of x
26 #ifdef __STDC__
27 static const unsigned
28 #else
29 static unsigned
30 #endif
31 B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
32 B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
34 #ifdef __STDC__
35 static const float
36 #else
37 static float
38 #endif
39 C = 5.4285717010e-01, /* 19/35 = 0x3f0af8b0 */
40 D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
41 E = 1.4142856598e+00, /* 99/70 = 0x3fb50750 */
42 F = 1.6071428061e+00, /* 45/28 = 0x3fcdb6db */
43 G = 3.5714286566e-01; /* 5/14 = 0x3eb6db6e */
45 #ifdef __STDC__
46 float __cbrtf(float x)
47 #else
48 float __cbrtf(x)
49 float x;
50 #endif
52 float r,s,t;
53 int32_t hx;
54 u_int32_t sign;
55 u_int32_t high;
57 GET_FLOAT_WORD(hx,x);
58 sign=hx&0x80000000; /* sign= sign(x) */
59 hx ^=sign;
60 if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
61 if(hx==0)
62 return(x); /* cbrt(0) is itself */
64 SET_FLOAT_WORD(x,hx); /* x <- |x| */
65 /* rough cbrt to 5 bits */
66 if(hx<0x00800000) /* subnormal number */
67 {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
68 t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
70 else
71 SET_FLOAT_WORD(t,hx/3+B1);
74 /* new cbrt to 23 bits */
75 r=t*t/x;
76 s=C+r*t;
77 t*=G+F/(s+E+D/s);
79 /* retore the sign bit */
80 GET_FLOAT_WORD(high,t);
81 SET_FLOAT_WORD(t,high|sign);
82 return(t);
84 weak_alias (__cbrtf, cbrtf)