OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [common/] [sf_cbrt.c] - Diff between revs 57 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 57 Rev 1765
/* sf_cbrt.c -- float version of s_cbrt.c.
/* sf_cbrt.c -- float version of s_cbrt.c.
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */
 */
 
 
/*
/*
 * ====================================================
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * software is freely granted, provided that this notice
 * is preserved.
 * is preserved.
 * ====================================================
 * ====================================================
 *
 *
 */
 */
 
 
#include "fdlibm.h"
#include "fdlibm.h"
 
 
/* cbrtf(x)
/* cbrtf(x)
 * Return cube root of x
 * Return cube root of x
 */
 */
#ifdef __STDC__
#ifdef __STDC__
static const __uint32_t
static const __uint32_t
#else
#else
static __uint32_t
static __uint32_t
#endif
#endif
        B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
        B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
        B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
        B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
 
 
#ifdef __STDC__
#ifdef __STDC__
static const float
static const float
#else
#else
static float
static float
#endif
#endif
C =  5.4285717010e-01, /* 19/35     = 0x3f0af8b0 */
C =  5.4285717010e-01, /* 19/35     = 0x3f0af8b0 */
D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
E =  1.4142856598e+00, /* 99/70     = 0x3fb50750 */
E =  1.4142856598e+00, /* 99/70     = 0x3fb50750 */
F =  1.6071428061e+00, /* 45/28     = 0x3fcdb6db */
F =  1.6071428061e+00, /* 45/28     = 0x3fcdb6db */
G =  3.5714286566e-01; /* 5/14      = 0x3eb6db6e */
G =  3.5714286566e-01; /* 5/14      = 0x3eb6db6e */
 
 
#ifdef __STDC__
#ifdef __STDC__
        float cbrtf(float x)
        float cbrtf(float x)
#else
#else
        float cbrtf(x)
        float cbrtf(x)
        float x;
        float x;
#endif
#endif
{
{
        __int32_t       hx;
        __int32_t       hx;
        float r,s,t;
        float r,s,t;
        __uint32_t sign;
        __uint32_t sign;
        __uint32_t high;
        __uint32_t high;
 
 
        GET_FLOAT_WORD(hx,x);
        GET_FLOAT_WORD(hx,x);
        sign=hx&0x80000000;             /* sign= sign(x) */
        sign=hx&0x80000000;             /* sign= sign(x) */
        hx  ^=sign;
        hx  ^=sign;
        if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
        if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
        if(hx==0)
        if(hx==0)
            return(x);          /* cbrt(0) is itself */
            return(x);          /* cbrt(0) is itself */
 
 
        SET_FLOAT_WORD(x,hx);   /* x <- |x| */
        SET_FLOAT_WORD(x,hx);   /* x <- |x| */
    /* rough cbrt to 5 bits */
    /* rough cbrt to 5 bits */
        if(hx<0x00800000)               /* subnormal number */
        if(hx<0x00800000)               /* subnormal number */
          {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
          {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
           t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
           t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
          }
          }
        else
        else
          SET_FLOAT_WORD(t,hx/3+B1);
          SET_FLOAT_WORD(t,hx/3+B1);
 
 
 
 
    /* new cbrt to 23 bits */
    /* new cbrt to 23 bits */
        r=t*t/x;
        r=t*t/x;
        s=C+r*t;
        s=C+r*t;
        t*=G+F/(s+E+D/s);
        t*=G+F/(s+E+D/s);
 
 
    /* retore the sign bit */
    /* retore the sign bit */
        GET_FLOAT_WORD(high,t);
        GET_FLOAT_WORD(high,t);
        SET_FLOAT_WORD(t,high|sign);
        SET_FLOAT_WORD(t,high|sign);
        return(t);
        return(t);
}
}
 
 
#ifdef _DOUBLE_IS_32BITS
#ifdef _DOUBLE_IS_32BITS
 
 
#ifdef __STDC__
#ifdef __STDC__
        double cbrt(double x)
        double cbrt(double x)
#else
#else
        double cbrt(x)
        double cbrt(x)
        double x;
        double x;
#endif
#endif
{
{
        return (double) cbrtf((float) x);
        return (double) cbrtf((float) x);
}
}
 
 
#endif /* defined(_DOUBLE_IS_32BITS) */
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.