12116Sjkh/* s_ilogbf.c -- float version of s_ilogb.c.
22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
32116Sjkh */
42116Sjkh
52116Sjkh/*
62116Sjkh * ====================================================
72116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
82116Sjkh *
92116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business.
102116Sjkh * Permission to use, copy, modify, and distribute this
118870Srgrimes * software is freely granted, provided that this notice
122116Sjkh * is preserved.
132116Sjkh * ====================================================
142116Sjkh */
152116Sjkh
16176451Sdas#include <sys/cdefs.h>
17176451Sdas__FBSDID("$FreeBSD$");
182116Sjkh
19136332Sstefanf#include <limits.h>
20136332Sstefanf
212116Sjkh#include "math.h"
222116Sjkh#include "math_private.h"
232116Sjkh
242116Sjkh	int ilogbf(float x)
252116Sjkh{
262116Sjkh	int32_t hx,ix;
272116Sjkh
282116Sjkh	GET_FLOAT_WORD(hx,x);
292116Sjkh	hx &= 0x7fffffff;
302116Sjkh	if(hx<0x00800000) {
318870Srgrimes	    if(hx==0)
32136332Sstefanf		return FP_ILOGB0;
332116Sjkh	    else			/* subnormal x */
342116Sjkh	        for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
352116Sjkh	    return ix;
362116Sjkh	}
372116Sjkh	else if (hx<0x7f800000) return (hx>>23)-127;
38136332Sstefanf	else if (hx>0x7f800000) return FP_ILOGBNAN;
39136332Sstefanf	else return INT_MAX;
402116Sjkh}
41