1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #if defined(LIBM_SCCS) && !defined(lint)
- static char rcsid[] = "$NetBSD: s_cbrt.c,v 1.8 1995/05/10 20:46:49 jtc Exp $";
- #endif
- #include "math.h"
- #include "math_private.h"
- #ifdef __STDC__
- static const u_int32_t
- #else
- static u_int32_t
- #endif
- B1 = 715094163,
- B2 = 696219795;
- #ifdef __STDC__
- static const double
- #else
- static double
- #endif
- C = 5.42857142857142815906e-01,
- D = -7.05306122448979611050e-01,
- E = 1.41428571428571436819e+00,
- F = 1.60714285714285720630e+00,
- G = 3.57142857142857150787e-01;
- libm_hidden_proto(cbrt)
- #ifdef __STDC__
- double cbrt(double x)
- #else
- double cbrt(x)
- double x;
- #endif
- {
- int32_t hx;
- double r,s,t=0.0,w;
- u_int32_t sign;
- u_int32_t high,low;
- GET_HIGH_WORD(hx,x);
- sign=hx&0x80000000;
- hx ^=sign;
- if(hx>=0x7ff00000) return(x+x);
- GET_LOW_WORD(low,x);
- if((hx|low)==0)
- return(x);
- SET_HIGH_WORD(x,hx);
-
- if(hx<0x00100000)
- {SET_HIGH_WORD(t,0x43500000);
- t*=x; GET_HIGH_WORD(high,t); SET_HIGH_WORD(t,high/3+B2);
- }
- else
- SET_HIGH_WORD(t,hx/3+B1);
-
- r=t*t/x;
- s=C+r*t;
- t*=G+F/(s+E+D/s);
-
- GET_HIGH_WORD(high,t);
- INSERT_WORDS(t,high+0x00000001,0);
-
- s=t*t;
- r=x/s;
- w=t+t;
- r=(r-t)/(w+r);
- t=t+t*r;
-
- GET_HIGH_WORD(high,t);
- SET_HIGH_WORD(t,high|sign);
- return(t);
- }
- libm_hidden_def(cbrt)
|