2 /* @(#)s_ilogb.c 5.1 93/09/24 */
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
11 * ====================================================
16 <<ilogb>>, <<ilogbf>>---get exponent of floating-point number
24 int ilogb(double <[val]>);
25 int ilogbf(float <[val]>);
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
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>>.
52 Neither <<ilogb>> nor <<ilogbf>> is required by ANSI C or by
53 the System V Interface Definition (Issue 2). */
56 * return the binary exponent of non-zero x
57 * ilogb(0) = 0x80000001
58 * ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
64 #ifndef _DOUBLE_IS_32BITS
75 EXTRACT_WORDS(hx
,lx
,x
);
79 return - INT_MAX
; /* ilogb(0) = 0x80000001 */
80 else /* subnormal x */
82 for (ix
= -1043; lx
>0; lx
<<=1) ix
-=1;
84 for (ix
= -1022,hx
<<=11; hx
>0; hx
<<=1) ix
-=1;
88 else if (hx
<0x7ff00000) return (hx
>>20)-1023;
92 #endif /* _DOUBLE_IS_32BITS */