source: vendor/FreeBSD-msun/current/src/s_cbrtf.c

Last change on this file was 2006, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.8 KB
Line 
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#ifndef lint
17static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cbrtf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
18#endif
19
20#include "math.h"
21#include "math_private.h"
22
23/* cbrtf(x)
24 * Return cube root of x
25 */
26static const unsigned
27 B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
28 B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
29
30static const float
31C = 5.4285717010e-01, /* 19/35 = 0x3f0af8b0 */
32D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
33E = 1.4142856598e+00, /* 99/70 = 0x3fb50750 */
34F = 1.6071428061e+00, /* 45/28 = 0x3fcdb6db */
35G = 3.5714286566e-01; /* 5/14 = 0x3eb6db6e */
36
37float
38cbrtf(float x)
39{
40 float r,s,t;
41 int32_t hx;
42 u_int32_t sign;
43 u_int32_t high;
44
45 GET_FLOAT_WORD(hx,x);
46 sign=hx&0x80000000; /* sign= sign(x) */
47 hx ^=sign;
48 if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
49 if(hx==0)
50 return(x); /* cbrt(0) is itself */
51
52 SET_FLOAT_WORD(x,hx); /* x <- |x| */
53 /* rough cbrt to 5 bits */
54 if(hx<0x00800000) /* subnormal number */
55 {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
56 t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
57 }
58 else
59 SET_FLOAT_WORD(t,hx/3+B1);
60
61
62 /* new cbrt to 23 bits */
63 r=t*t/x;
64 s=C+r*t;
65 t*=G+F/(s+E+D/s);
66
67 /* retore the sign bit */
68 GET_FLOAT_WORD(high,t);
69 SET_FLOAT_WORD(t,high|sign);
70 return(t);
71}
Note: See TracBrowser for help on using the repository browser.