12fe8fb19SBen Gras /* s_ilogbf.c -- float version of s_ilogb.c.
22fe8fb19SBen Gras * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
32fe8fb19SBen Gras */
42fe8fb19SBen Gras
52fe8fb19SBen Gras /*
62fe8fb19SBen Gras * ====================================================
72fe8fb19SBen Gras * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
82fe8fb19SBen Gras *
92fe8fb19SBen Gras * Developed at SunPro, a Sun Microsystems, Inc. business.
102fe8fb19SBen Gras * Permission to use, copy, modify, and distribute this
112fe8fb19SBen Gras * software is freely granted, provided that this notice
122fe8fb19SBen Gras * is preserved.
132fe8fb19SBen Gras * ====================================================
142fe8fb19SBen Gras */
152fe8fb19SBen Gras
162fe8fb19SBen Gras #include <sys/cdefs.h>
172fe8fb19SBen Gras #if defined(LIBM_SCCS) && !defined(lint)
18*84d9c625SLionel Sambuc __RCSID("$NetBSD: s_ilogbf.c,v 1.8 2013/02/09 22:56:00 matt Exp $");
192fe8fb19SBen Gras #endif
202fe8fb19SBen Gras
212fe8fb19SBen Gras #include "math.h"
222fe8fb19SBen Gras #include "math_private.h"
232fe8fb19SBen Gras
242fe8fb19SBen Gras int
ilogbf(float x)252fe8fb19SBen Gras ilogbf(float x)
262fe8fb19SBen Gras {
272fe8fb19SBen Gras int32_t hx,ix;
282fe8fb19SBen Gras
292fe8fb19SBen Gras GET_FLOAT_WORD(hx,x);
302fe8fb19SBen Gras hx &= 0x7fffffff;
312fe8fb19SBen Gras if(hx<0x00800000) {
322fe8fb19SBen Gras if(hx==0)
33*84d9c625SLionel Sambuc return FP_ILOGB0; /* ilogb(0) = 0x80000001 */
342fe8fb19SBen Gras else /* subnormal x */
352fe8fb19SBen Gras for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
362fe8fb19SBen Gras return ix;
372fe8fb19SBen Gras }
382fe8fb19SBen Gras else if (hx<0x7f800000) return (hx>>23)-127;
39*84d9c625SLionel Sambuc else return FP_ILOGBNAN; /* inf too */
402fe8fb19SBen Gras }
41