Blame sysdeps/ieee754/flt-32/e_ilogbf.c

Packit 6c4009
/* s_ilogbf.c -- float version of s_ilogb.c.
Packit 6c4009
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * ====================================================
Packit 6c4009
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
Packit 6c4009
 *
Packit 6c4009
 * Developed at SunPro, a Sun Microsystems, Inc. business.
Packit 6c4009
 * Permission to use, copy, modify, and distribute this
Packit 6c4009
 * software is freely granted, provided that this notice
Packit 6c4009
 * is preserved.
Packit 6c4009
 * ====================================================
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#if defined(LIBM_SCCS) && !defined(lint)
Packit 6c4009
static char rcsid[] = "$NetBSD: s_ilogbf.c,v 1.4 1995/05/10 20:47:31 jtc Exp $";
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#include <limits.h>
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
Packit 6c4009
int __ieee754_ilogbf(float x)
Packit 6c4009
{
Packit 6c4009
	int32_t hx,ix;
Packit 6c4009
Packit 6c4009
	GET_FLOAT_WORD(hx,x);
Packit 6c4009
	hx &= 0x7fffffff;
Packit 6c4009
	if(hx<0x00800000) {
Packit 6c4009
	    if(hx==0)
Packit 6c4009
		return FP_ILOGB0;	/* ilogb(0) = FP_ILOGB0 */
Packit 6c4009
	    else			/* subnormal x */
Packit 6c4009
	        for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
Packit 6c4009
	    return ix;
Packit 6c4009
	}
Packit 6c4009
	else if (hx<0x7f800000) return (hx>>23)-127;
Packit 6c4009
	else if (FP_ILOGBNAN != INT_MAX) {
Packit 6c4009
	    /* ISO C99 requires ilogbf(+-Inf) == INT_MAX.  */
Packit 6c4009
	    if (hx==0x7f800000)
Packit 6c4009
		return INT_MAX;
Packit 6c4009
	}
Packit 6c4009
	return FP_ILOGBNAN;
Packit 6c4009
}