OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libm/] [common/] [sf_logb.c] - Diff between revs 207 and 345

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

Rev 207 Rev 345
/* 2009 for Newlib:  Sun's sf_ilogb.c converted to be sf_logb.c.  */
/* 2009 for Newlib:  Sun's sf_ilogb.c converted to be sf_logb.c.  */
/*
/*
 * ====================================================
 * ====================================================
 * 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.
 * ====================================================
 * ====================================================
 */
 */
 
 
/* float logb(float x)
/* float logb(float x)
 * return the binary exponent of non-zero x
 * return the binary exponent of non-zero x
 * logbf(0) = -inf, raise divide-by-zero floating point exception
 * logbf(0) = -inf, raise divide-by-zero floating point exception
 * logbf(+inf|-inf) = +inf (no signal is raised)
 * logbf(+inf|-inf) = +inf (no signal is raised)
 * logbf(NaN) = NaN (no signal is raised)
 * logbf(NaN) = NaN (no signal is raised)
 * Per C99 recommendation, a NaN argument is returned unchanged.
 * Per C99 recommendation, a NaN argument is returned unchanged.
 */
 */
 
 
#include "fdlibm.h"
#include "fdlibm.h"
 
 
float
float
#ifdef __STDC__
#ifdef __STDC__
logbf(float x)
logbf(float x)
#else
#else
logbf(x)
logbf(x)
float x;
float x;
#endif
#endif
{
{
        __int32_t hx,ix;
        __int32_t hx,ix;
 
 
        GET_FLOAT_WORD(hx,x);
        GET_FLOAT_WORD(hx,x);
        hx &= 0x7fffffff;
        hx &= 0x7fffffff;
        if(FLT_UWORD_IS_ZERO(hx))  {
        if(FLT_UWORD_IS_ZERO(hx))  {
                float  xx;
                float  xx;
                /* arg==0:  return -inf and raise divide-by-zero exception */
                /* arg==0:  return -inf and raise divide-by-zero exception */
                SET_FLOAT_WORD(xx,hx);  /* +0.0 */
                SET_FLOAT_WORD(xx,hx);  /* +0.0 */
                return -1./xx;  /* logbf(0) = -inf */
                return -1./xx;  /* logbf(0) = -inf */
                }
                }
        if(FLT_UWORD_IS_SUBNORMAL(hx)) {
        if(FLT_UWORD_IS_SUBNORMAL(hx)) {
            for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
            for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
            return (float) ix;
            return (float) ix;
        }
        }
        else if (FLT_UWORD_IS_INFINITE(hx)) return HUGE_VALF;   /* x==+|-inf */
        else if (FLT_UWORD_IS_INFINITE(hx)) return HUGE_VALF;   /* x==+|-inf */
        else if (FLT_UWORD_IS_NAN(hx)) return x;
        else if (FLT_UWORD_IS_NAN(hx)) return x;
        else return (float) ((hx>>23)-127);
        else return (float) ((hx>>23)-127);
}
}
 
 
#ifdef _DOUBLE_IS_32BITS
#ifdef _DOUBLE_IS_32BITS
 
 
#ifdef __STDC__
#ifdef __STDC__
        double logb(double x)
        double logb(double x)
#else
#else
        double logb(x)
        double logb(x)
        double x;
        double x;
#endif
#endif
{
{
        return (double) logbf((float) x);
        return (double) logbf((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.