1 /* sf_ilogb.c -- float version of s_ilogb.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  */
4 
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
9  * Developed at SunPro, a Sun Microsystems, Inc. business.
10  * Permission to use, copy, modify, and distribute this
11  * software is freely granted, provided that this notice
12  * is preserved.
13  * ====================================================
14  */
15 
16 #include <limits.h>
17 #include "fdlibm.h"
18 
ilogbf(float x)19 int ilogbf(float x)
20 {
21 	__int32_t hx,ix;
22 
23 	GET_FLOAT_WORD(hx,x);
24 	hx &= 0x7fffffff;
25 	if(FLT_UWORD_IS_ZERO(hx)) {
26             (void) __math_invalidf(0.0);
27 	    return FP_ILOGB0;	/* ilogb(0) = special case error */
28         }
29 	if(FLT_UWORD_IS_SUBNORMAL(hx)) {
30 	    for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
31 	    return ix;
32 	}
33 #if FP_ILOGBNAN != INT_MAX
34 	else if (FLT_UWORD_IS_NAN(hx)) {
35             (void) __math_invalidf(0.0);
36             return FP_ILOGBNAN;	/* NAN */
37         }
38 #endif
39 	else if (!FLT_UWORD_IS_FINITE(hx)) {
40             (void) __math_invalidf(0.0);
41             return INT_MAX;
42         }
43 	else return (hx>>23)-127;
44 }
45 
46 _MATH_ALIAS_i_f(ilogb)
47