s_ilogbf.c revision 136332
166458Sdfr/* s_ilogbf.c -- float version of s_ilogb.c.
2145092Smarcel * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
366458Sdfr */
466458Sdfr
566458Sdfr/*
666458Sdfr * ====================================================
766458Sdfr * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
866458Sdfr *
966458Sdfr * Developed at SunPro, a Sun Microsystems, Inc. business.
1066458Sdfr * Permission to use, copy, modify, and distribute this
1166458Sdfr * software is freely granted, provided that this notice
1266458Sdfr * is preserved.
1366458Sdfr * ====================================================
1466458Sdfr */
1566458Sdfr
1666458Sdfr#ifndef lint
1766458Sdfrstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_ilogbf.c 136332 2004-10-09 17:14:28Z stefanf $";
1866458Sdfr#endif
1966458Sdfr
2066458Sdfr#include <limits.h>
2166458Sdfr
2266458Sdfr#include "math.h"
2366458Sdfr#include "math_private.h"
2466458Sdfr
2566458Sdfr	int ilogbf(float x)
2666458Sdfr{
2766458Sdfr	int32_t hx,ix;
28145092Smarcel
29145092Smarcel	GET_FLOAT_WORD(hx,x);
30145092Smarcel	hx &= 0x7fffffff;
31118239Speter	if(hx<0x00800000) {
32118239Speter	    if(hx==0)
3366458Sdfr		return FP_ILOGB0;
3466458Sdfr	    else			/* subnormal x */
3566458Sdfr	        for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
3666458Sdfr	    return ix;
37171740Smarcel	}
38192918Srink	else if (hx<0x7f800000) return (hx>>23)-127;
3966458Sdfr	else if (hx>0x7f800000) return FP_ILOGBNAN;
4066458Sdfr	else return INT_MAX;
4174733Sjhb}
4266458Sdfr