fixed more binutils issues (newer gcc/libc)
[zpugcc/jano.git] / toolchain / gcc / newlib / libm / common / s_ilogb.c
blob00dfef6336c8b2615a8b71b830169826316f8273
2 /* @(#)s_ilogb.c 5.1 93/09/24 */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
15 FUNCTION
16 <<ilogb>>, <<ilogbf>>---get exponent of floating-point number
17 INDEX
18 ilogb
19 INDEX
20 ilogbf
22 ANSI_SYNOPSIS
23 #include <math.h>
24 int ilogb(double <[val]>);
25 int ilogbf(float <[val]>);
27 TRAD_SYNOPSIS
28 #include <math.h>
29 int ilogb(<[val]>)
30 double <[val]>;
32 int ilogbf(<[val]>)
33 float <[val]>;
36 DESCRIPTION
38 All nonzero, 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]>.
44 RETURNS
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>>.
51 PORTABILITY
52 Neither <<ilogb>> nor <<ilogbf>> is required by ANSI C or by
53 the System V Interface Definition (Issue 2). */
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)
61 #include "fdlibm.h"
62 #include <limits.h>
64 #ifndef _DOUBLE_IS_32BITS
66 #ifdef __STDC__
67 int ilogb(double x)
68 #else
69 int ilogb(x)
70 double x;
71 #endif
73 __int32_t hx,lx,ix;
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;
86 return ix;
88 else if (hx<0x7ff00000) return (hx>>20)-1023;
89 else return INT_MAX;
92 #endif /* _DOUBLE_IS_32BITS */