2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
13 * return the binary exponent of x
14 * ilogb(+-0) = FP_ILOGB0
15 * ilogb(+-inf) = INT_MAX
16 * ilogb(NaN) = FP_ILOGBNAN (no signal is raised)
20 #include "math_private.h"
29 if (hx
< 0x00100000) {
31 if ((hx
|lx
)==0) /* +-0, ilogb(0) = FP_ILOGB0 */
39 /* each leading zero mantissa bit makes exponent smaller */
40 for (; lx
> 0; lx
<<= 1)
45 if (hx
< 0x7ff00000) /* normal x */
46 return (hx
>>20) - 1023;
48 if (FP_ILOGBNAN
!= (~0U >> 1)) {
50 if (hx
== 0x7ff00000 && lx
== 0) /* +-inf */
51 return ~0U >> 1; /* = INT_MAX */
54 /* NAN. ilogb(NAN) = FP_ILOGBNAN */
57 libm_hidden_def(ilogb
)