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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libm/] [math/] [s_frexp.c] - Blame information for rev 313

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
 
2
/* @(#)s_frexp.c 5.1 93/09/24 */
3
/*
4
 * ====================================================
5
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6
 *
7
 * Developed at SunPro, a Sun Microsystems, Inc. business.
8
 * Permission to use, copy, modify, and distribute this
9
 * software is freely granted, provided that this notice
10
 * is preserved.
11
 * ====================================================
12
 */
13
 
14
/*
15
FUNCTION
16
       <<frexp>>, <<frexpf>>---split floating-point number
17
INDEX
18
        frexp
19
INDEX
20
        frexpf
21
 
22
ANSI_SYNOPSIS
23
        #include <math.h>
24
        double frexp(double <[val]>, int *<[exp]>);
25
        float frexpf(float <[val]>, int *<[exp]>);
26
 
27
TRAD_SYNOPSIS
28
        #include <math.h>
29
        double frexp(<[val]>, <[exp]>)
30
        double <[val]>;
31
        int *<[exp]>;
32
 
33
        float frexpf(<[val]>, <[exp]>)
34
        float <[val]>;
35
        int *<[exp]>;
36
 
37
 
38
DESCRIPTION
39
        All nonzero, normal numbers can be described as <[m]> * 2**<[p]>.
40
        <<frexp>> represents the double <[val]> as a mantissa <[m]>
41
        and a power of two <[p]>. The resulting mantissa will always
42
        be greater than or equal to <<0.5>>, and less than <<1.0>> (as
43
        long as <[val]> is nonzero). The power of two will be stored
44
        in <<*>><[exp]>.
45
 
46
@ifnottex
47
<[m]> and <[p]> are calculated so that
48
<[val]> is <[m]> times <<2>> to the power <[p]>.
49
@end ifnottex
50
@tex
51
<[m]> and <[p]> are calculated so that
52
$ val = m \times 2^p $.
53
@end tex
54
 
55
<<frexpf>> is identical, other than taking and returning
56
floats rather than doubles.
57
 
58
RETURNS
59
<<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
60
or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
61
 
62
PORTABILITY
63
<<frexp>> is ANSI.
64
<<frexpf>> is an extension.
65
 
66
 
67
*/
68
 
69
/*
70
 * for non-zero x
71
 *      x = frexp(arg,&exp);
72
 * return a double fp quantity x such that 0.5 <= |x| <1.0
73
 * and the corresponding binary exponent "exp". That is
74
 *      arg = x*2^exp.
75
 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
76
 * with *exp=0.
77
 */
78
 
79
#include "fdlibm.h"
80
 
81
#ifndef _DOUBLE_IS_32BITS
82
 
83
#ifdef __STDC__
84
static const double
85
#else
86
static double
87
#endif
88
two54 =  1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
89
 
90
#ifdef __STDC__
91
        double frexp(double x, int *eptr)
92
#else
93
        double frexp(x, eptr)
94
        double x; int *eptr;
95
#endif
96
{
97
        __int32_t hx, ix, lx;
98
        EXTRACT_WORDS(hx,lx,x);
99
        ix = 0x7fffffff&hx;
100
        *eptr = 0;
101
        if(ix>=0x7ff00000||((ix|lx)==0)) return x;       /* 0,inf,nan */
102
        if (ix<0x00100000) {            /* subnormal */
103
            x *= two54;
104
            GET_HIGH_WORD(hx,x);
105
            ix = hx&0x7fffffff;
106
            *eptr = -54;
107
        }
108
        *eptr += (ix>>20)-1022;
109
        hx = (hx&0x800fffff)|0x3fe00000;
110
        SET_HIGH_WORD(x,hx);
111
        return x;
112
}
113
 
114
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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