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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [common/] [s_ilogb.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 joel
 
2
/* @(#)s_ilogb.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
       <<ilogb>>, <<ilogbf>>---get exponent of floating point number
17
INDEX
18
        ilogb
19
INDEX
20
        ilogbf
21
 
22
ANSI_SYNOPSIS
23
        #include <math.h>
24
        int ilogb(double <[val]>);
25
        int ilogbf(float <[val]>);
26
 
27
TRAD_SYNOPSIS
28
        #include <math.h>
29
        int ilogb(<[val]>)
30
        double <[val]>;
31
 
32
        int ilogbf(<[val]>)
33
        float <[val]>;
34
 
35
 
36
DESCRIPTION
37
 
38
        All non zero, normal numbers can be described as <[m]> *
39
        2**<[p]>.  <<ilogb>> and <<ilogbf>> examine the argument
40
        <[val]>, and return <[p]>.  The functions <<frexp>> and
41
        <<frexpf>> are similar to <<ilogb>> and <<ilogbf>>, but also
42
        return <[m]>.
43
 
44
RETURNS
45
 
46
<<ilogb>> and <<ilogbf>> return the power of two used to form the
47
floating point argument.  If <[val]> is <<0>>, they return <<-
48
INT_MAX>> (<<INT_MAX>> is defined in limits.h).  If <[val]> is
49
infinite, or NaN, they return <<INT_MAX>>.
50
 
51
PORTABILITY
52
        Neither <<ilogb>> nor <<ilogbf>> is required by ANSI C or by
53
        the System V Interface Definition (Issue 2).  */
54
 
55
/* ilogb(double x)
56
 * return the binary exponent of non-zero x
57
 * ilogb(0) = 0x80000001
58
 * ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
59
 */
60
 
61
#include "fdlibm.h"
62
#include <limits.h>
63
 
64
#ifndef _DOUBLE_IS_32BITS
65
 
66
#ifdef __STDC__
67
        int ilogb(double x)
68
#else
69
        int ilogb(x)
70
        double x;
71
#endif
72
{
73
        __int32_t hx,lx,ix;
74
 
75
        EXTRACT_WORDS(hx,lx,x);
76
        hx &= 0x7fffffff;
77
        if(hx<0x00100000) {
78
            if((hx|lx)==0)
79
                return - INT_MAX;       /* ilogb(0) = 0x80000001 */
80
            else                        /* subnormal x */
81
                if(hx==0) {
82
                    for (ix = -1043; lx>0; lx<<=1) ix -=1;
83
                } else {
84
                    for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
85
                }
86
            return ix;
87
        }
88
        else if (hx<0x7ff00000) return (hx>>20)-1023;
89
        else return INT_MAX;
90
}
91
 
92
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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