Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / msun / src / s_cbrtf.c
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  * $FreeBSD: src/lib/msun/src/s_cbrtf.c,v 1.5 1999/08/28 00:06:44 peter Exp $
5  * $DragonFly: src/lib/msun/src/Attic/s_cbrtf.c,v 1.2 2003/06/17 04:26:53 dillon Exp $
6  */
7
8 /*
9  * ====================================================
10  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11  *
12  * Developed at SunPro, a Sun Microsystems, Inc. business.
13  * Permission to use, copy, modify, and distribute this
14  * software is freely granted, provided that this notice
15  * is preserved.
16  * ====================================================
17  */
18
19 #include "math.h"
20 #include "math_private.h"
21
22 /* cbrtf(x)
23  * Return cube root of x
24  */
25 #ifdef __STDC__
26 static const unsigned
27 #else
28 static unsigned
29 #endif
30         B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
31         B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
32
33 #ifdef __STDC__
34 static const float
35 #else
36 static float
37 #endif
38 C =  5.4285717010e-01, /* 19/35     = 0x3f0af8b0 */
39 D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
40 E =  1.4142856598e+00, /* 99/70     = 0x3fb50750 */
41 F =  1.6071428061e+00, /* 45/28     = 0x3fcdb6db */
42 G =  3.5714286566e-01; /* 5/14      = 0x3eb6db6e */
43
44 #ifdef __STDC__
45         float cbrtf(float x)
46 #else
47         float cbrtf(x)
48         float x;
49 #endif
50 {
51         float r,s,t;
52         int32_t hx;
53         u_int32_t sign;
54         u_int32_t high;
55
56         GET_FLOAT_WORD(hx,x);
57         sign=hx&0x80000000;             /* sign= sign(x) */
58         hx  ^=sign;
59         if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
60         if(hx==0)
61             return(x);          /* cbrt(0) is itself */
62
63         SET_FLOAT_WORD(x,hx);   /* x <- |x| */
64     /* rough cbrt to 5 bits */
65         if(hx<0x00800000)               /* subnormal number */
66           {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
67            t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
68           }
69         else
70           SET_FLOAT_WORD(t,hx/3+B1);
71
72
73     /* new cbrt to 23 bits */
74         r=t*t/x;
75         s=C+r*t;
76         t*=G+F/(s+E+D/s);
77
78     /* retore the sign bit */
79         GET_FLOAT_WORD(high,t);
80         SET_FLOAT_WORD(t,high|sign);
81         return(t);
82 }