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/] [math/] [s_frexp.c] - Diff between revs 207 and 345

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

Rev 207 Rev 345
 
 
/* @(#)s_frexp.c 5.1 93/09/24 */
/* @(#)s_frexp.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
       <<frexp>>, <<frexpf>>---split floating-point number
       <<frexp>>, <<frexpf>>---split floating-point number
INDEX
INDEX
        frexp
        frexp
INDEX
INDEX
        frexpf
        frexpf
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double frexp(double <[val]>, int *<[exp]>);
        double frexp(double <[val]>, int *<[exp]>);
        float frexpf(float <[val]>, int *<[exp]>);
        float frexpf(float <[val]>, int *<[exp]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double frexp(<[val]>, <[exp]>)
        double frexp(<[val]>, <[exp]>)
        double <[val]>;
        double <[val]>;
        int *<[exp]>;
        int *<[exp]>;
 
 
        float frexpf(<[val]>, <[exp]>)
        float frexpf(<[val]>, <[exp]>)
        float <[val]>;
        float <[val]>;
        int *<[exp]>;
        int *<[exp]>;
 
 
 
 
DESCRIPTION
DESCRIPTION
        All nonzero, normal numbers can be described as <[m]> * 2**<[p]>.
        All nonzero, normal numbers can be described as <[m]> * 2**<[p]>.
        <<frexp>> represents the double <[val]> as a mantissa <[m]>
        <<frexp>> represents the double <[val]> as a mantissa <[m]>
        and a power of two <[p]>. The resulting mantissa will always
        and a power of two <[p]>. The resulting mantissa will always
        be greater than or equal to <<0.5>>, and less than <<1.0>> (as
        be greater than or equal to <<0.5>>, and less than <<1.0>> (as
        long as <[val]> is nonzero). The power of two will be stored
        long as <[val]> is nonzero). The power of two will be stored
        in <<*>><[exp]>.
        in <<*>><[exp]>.
 
 
@ifnottex
@ifnottex
<[m]> and <[p]> are calculated so that
<[m]> and <[p]> are calculated so that
<[val]> is <[m]> times <<2>> to the power <[p]>.
<[val]> is <[m]> times <<2>> to the power <[p]>.
@end ifnottex
@end ifnottex
@tex
@tex
<[m]> and <[p]> are calculated so that
<[m]> and <[p]> are calculated so that
$ val = m \times 2^p $.
$ val = m \times 2^p $.
@end tex
@end tex
 
 
<<frexpf>> is identical, other than taking and returning
<<frexpf>> is identical, other than taking and returning
floats rather than doubles.
floats rather than doubles.
 
 
RETURNS
RETURNS
<<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
<<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
 
 
PORTABILITY
PORTABILITY
<<frexp>> is ANSI.
<<frexp>> is ANSI.
<<frexpf>> is an extension.
<<frexpf>> is an extension.
 
 
 
 
*/
*/
 
 
/*
/*
 * for non-zero x
 * for non-zero x
 *      x = frexp(arg,&exp);
 *      x = frexp(arg,&exp);
 * return a double fp quantity x such that 0.5 <= |x| <1.0
 * return a double fp quantity x such that 0.5 <= |x| <1.0
 * and the corresponding binary exponent "exp". That is
 * and the corresponding binary exponent "exp". That is
 *      arg = x*2^exp.
 *      arg = x*2^exp.
 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
 * with *exp=0.
 * with *exp=0.
 */
 */
 
 
#include "fdlibm.h"
#include "fdlibm.h"
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
#ifdef __STDC__
#ifdef __STDC__
static const double
static const double
#else
#else
static double
static double
#endif
#endif
two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
 
 
#ifdef __STDC__
#ifdef __STDC__
        double frexp(double x, int *eptr)
        double frexp(double x, int *eptr)
#else
#else
        double frexp(x, eptr)
        double frexp(x, eptr)
        double x; int *eptr;
        double x; int *eptr;
#endif
#endif
{
{
        __int32_t hx, ix, lx;
        __int32_t hx, ix, lx;
        EXTRACT_WORDS(hx,lx,x);
        EXTRACT_WORDS(hx,lx,x);
        ix = 0x7fffffff&hx;
        ix = 0x7fffffff&hx;
        *eptr = 0;
        *eptr = 0;
        if(ix>=0x7ff00000||((ix|lx)==0)) return x;       /* 0,inf,nan */
        if(ix>=0x7ff00000||((ix|lx)==0)) return x;       /* 0,inf,nan */
        if (ix<0x00100000) {            /* subnormal */
        if (ix<0x00100000) {            /* subnormal */
            x *= two54;
            x *= two54;
            GET_HIGH_WORD(hx,x);
            GET_HIGH_WORD(hx,x);
            ix = hx&0x7fffffff;
            ix = hx&0x7fffffff;
            *eptr = -54;
            *eptr = -54;
        }
        }
        *eptr += (ix>>20)-1022;
        *eptr += (ix>>20)-1022;
        hx = (hx&0x800fffff)|0x3fe00000;
        hx = (hx&0x800fffff)|0x3fe00000;
        SET_HIGH_WORD(x,hx);
        SET_HIGH_WORD(x,hx);
        return x;
        return x;
}
}
 
 
#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.