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/] [s_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 s_ilogb.c converted to be s_logb.c.  */
/* 2009 for Newlib:  Sun's s_ilogb.c converted to be s_logb.c.  */
/* @(#)s_ilogb.c 5.1 93/09/24 */
/* @(#)s_ilogb.c 5.1 93/09/24 */
/*
/*
 * ====================================================
 * ====================================================
 * 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.
 * ====================================================
 * ====================================================
 */
 */
/*
/*
FUNCTION
FUNCTION
       <<logb>>, <<logbf>>--get exponent of floating-point number
       <<logb>>, <<logbf>>--get exponent of floating-point number
INDEX
INDEX
        logb
        logb
INDEX
INDEX
        logbf
        logbf
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double logb(double <[x]>);
        double logb(double <[x]>);
        float logbf(float <[x]>);
        float logbf(float <[x]>);
 
 
DESCRIPTION
DESCRIPTION
The <<logb>> functions extract the exponent of <[x]>, as a signed integer value
The <<logb>> functions extract the exponent of <[x]>, as a signed integer value
in floating-point format.  If <[x]> is subnormal it is treated as though it were
in floating-point format.  If <[x]> is subnormal it is treated as though it were
normalized; thus, for positive finite <[x]>,
normalized; thus, for positive finite <[x]>,
@ifnottex
@ifnottex
1 <= (<[x]> * FLT_RADIX to the power (-logb(<[x]>))) < FLT_RADIX.
1 <= (<[x]> * FLT_RADIX to the power (-logb(<[x]>))) < FLT_RADIX.
@end ifnottex
@end ifnottex
@tex
@tex
$1 \leq ( x \cdot FLT\_RADIX ^ {-logb(x)} ) < FLT\_RADIX$.
$1 \leq ( x \cdot FLT\_RADIX ^ {-logb(x)} ) < FLT\_RADIX$.
@end tex
@end tex
A domain error may occur if the argument is zero.
A domain error may occur if the argument is zero.
In this floating-point implementation, FLT_RADIX is 2.  Which also means
In this floating-point implementation, FLT_RADIX is 2.  Which also means
that for finite <[x]>, <<logb>>(<[x]>) = <<floor>>(<<log2>>(<<fabs>>(<[x]>))).
that for finite <[x]>, <<logb>>(<[x]>) = <<floor>>(<<log2>>(<<fabs>>(<[x]>))).
 
 
All nonzero, normal numbers can be described as
All nonzero, normal numbers can be described as
@ifnottex
@ifnottex
<[m]> * 2**<[p]>, where 1.0 <= <[m]> < 2.0.
<[m]> * 2**<[p]>, where 1.0 <= <[m]> < 2.0.
@end ifnottex
@end ifnottex
@tex
@tex
$m \cdot 2^p$, where $1.0 \leq m < 2.0$.
$m \cdot 2^p$, where $1.0 \leq m < 2.0$.
@end tex
@end tex
The <<logb>> functions examine the argument <[x]>, and return <[p]>.
The <<logb>> functions examine the argument <[x]>, and return <[p]>.
The <<frexp>> functions are similar to the <<logb>> functions, but
The <<frexp>> functions are similar to the <<logb>> functions, but
returning <[m]> adjusted to the interval [.5, 1) or 0, and <[p]>+1.
returning <[m]> adjusted to the interval [.5, 1) or 0, and <[p]>+1.
 
 
RETURNS
RETURNS
@comment Formatting note:  "$@" forces a new line
@comment Formatting note:  "$@" forces a new line
When <[x]> is:@*
When <[x]> is:@*
+inf or -inf, +inf is returned;@*
+inf or -inf, +inf is returned;@*
NaN, NaN is returned;@*
NaN, NaN is returned;@*
0, -inf is returned, and the divide-by-zero exception is raised;@*
0, -inf is returned, and the divide-by-zero exception is raised;@*
otherwise, the <<logb>> functions return the signed exponent of <[x]>.
otherwise, the <<logb>> functions return the signed exponent of <[x]>.
 
 
PORTABILITY
PORTABILITY
ANSI C, POSIX
ANSI C, POSIX
 
 
SEEALSO
SEEALSO
frexp, ilogb
frexp, ilogb
*/
*/
 
 
/* double logb(double x)
/* double logb(double x)
 * return the binary exponent of non-zero x
 * return the binary exponent of non-zero x
 * logb(0) = -inf, raise divide-by-zero floating point exception
 * logb(0) = -inf, raise divide-by-zero floating point exception
 * logb(+inf|-inf) = +inf (no signal is raised)
 * logb(+inf|-inf) = +inf (no signal is raised)
 * logb(NaN) = NaN (no signal is raised)
 * logb(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"
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
double
double
#ifdef __STDC__
#ifdef __STDC__
logb(double x)
logb(double x)
#else
#else
logb(x)
logb(x)
double x;
double x;
#endif
#endif
{
{
        __int32_t hx,lx,ix;
        __int32_t hx,lx,ix;
 
 
        EXTRACT_WORDS(hx,lx,x);
        EXTRACT_WORDS(hx,lx,x);
        hx &= 0x7fffffff;               /* high |x| */
        hx &= 0x7fffffff;               /* high |x| */
        if(hx<0x00100000) {             /* 0 or subnormal */
        if(hx<0x00100000) {             /* 0 or subnormal */
            if((hx|lx)==0)  {
            if((hx|lx)==0)  {
                double  xx;
                double  xx;
                /* arg==0:  return -inf and raise divide-by-zero exception */
                /* arg==0:  return -inf and raise divide-by-zero exception */
                INSERT_WORDS(xx,hx,lx); /* +0.0 */
                INSERT_WORDS(xx,hx,lx); /* +0.0 */
                return -1./xx;  /* logb(0) = -inf */
                return -1./xx;  /* logb(0) = -inf */
                }
                }
            else                        /* subnormal x */
            else                        /* subnormal x */
                if(hx==0) {
                if(hx==0) {
                    for (ix = -1043; lx>0; lx<<=1) ix -=1;
                    for (ix = -1043; lx>0; lx<<=1) ix -=1;
                } else {
                } else {
                    for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
                    for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
                }
                }
            return (double) ix;
            return (double) ix;
        }
        }
        else if (hx<0x7ff00000) return (hx>>20)-1023;   /* normal # */
        else if (hx<0x7ff00000) return (hx>>20)-1023;   /* normal # */
        else if (hx>0x7ff00000 || lx)  return x;        /* x==NaN */
        else if (hx>0x7ff00000 || lx)  return x;        /* x==NaN */
        else  return HUGE_VAL;  /* x==inf (+ or -) */
        else  return HUGE_VAL;  /* x==inf (+ or -) */
}
}
 
 
#endif /* _DOUBLE_IS_32BITS */
#endif /* _DOUBLE_IS_32BITS */
 
 

powered by: WebSVN 2.1.0

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