Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
s_cbrt.c File Reference
#include "fdlibm.h"

Go to the source code of this file.

Functions

double fd_cbrt (double x)

Variables

static unsigned B1 = 715094163
static unsigned B2 = 696219795
static double C = 5.42857142857142815906e-01
static double D = -7.05306122448979611050e-01
static double E = 1.41428571428571436819e+00
static double F = 1.60714285714285720630e+00
static double G = 3.57142857142857150787e-01

Function Documentation

double fd_cbrt ( double  x)

Definition at line 80 of file s_cbrt.c.

{
        fd_twoints u;
       int    hx;
       double r,s,t=0.0,w;
       unsigned sign;

        u.d = x;
       hx = __HI(u);        /* high word of x */
       sign=hx&0x80000000;         /* sign= sign(x) */
       hx  ^=sign;
       if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
       if((hx|__LO(u))==0) {
            x = u.d;
           return(x);              /* cbrt(0) is itself */
        }
        u.d = x;
       __HI(u) = hx; /* x <- |x| */
        x = u.d;
    /* rough cbrt to 5 bits */
       if(hx<0x00100000)           /* subnormal number */
         {u.d = t; __HI(u)=0x43500000; t=u.d;           /* set t= 2**54 */
          t*=x; __HI(u)=__HI(u)/3+B2;
         }
       else {
         u.d = t; __HI(u)=hx/3+B1; t = u.d;
        }


    /* new cbrt to 23 bits, may be implemented in single precision */
       r=t*t/x;
       s=C+r*t;
       t*=G+F/(s+E+D/s);    

    /* chopped to 20 bits and make it larger than cbrt(x) */ 
        u.d = t;
       __LO(u)=0; __HI(u)+=0x00000001;
        t = u.d;

    /* one step newton iteration to 53 bits with error less than 0.667 ulps */
       s=t*t;        /* t*t is exact */
       r=x/s;
       w=t+t;
       r=(r-t)/(w+r);       /* r-s is exact */
       t=t+t*r;

    /* retore the sign bit */
        u.d = t;
       __HI(u) |= sign;
        t = u.d;
       return(t);
}

Variable Documentation

unsigned B1 = 715094163 [static]

Definition at line 63 of file s_cbrt.c.

unsigned B2 = 696219795 [static]

Definition at line 64 of file s_cbrt.c.

double C = 5.42857142857142815906e-01 [static]

Definition at line 71 of file s_cbrt.c.

double D = -7.05306122448979611050e-01 [static]

Definition at line 72 of file s_cbrt.c.

double E = 1.41428571428571436819e+00 [static]

Definition at line 73 of file s_cbrt.c.

double F = 1.60714285714285720630e+00 [static]

Definition at line 74 of file s_cbrt.c.

double G = 3.57142857142857150787e-01 [static]

Definition at line 75 of file s_cbrt.c.