Back to index

glibc  2.9
s_ilogbf.c
Go to the documentation of this file.
00001 /* s_ilogbf.c -- float version of s_ilogb.c.
00002  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: s_ilogbf.c,v 1.4 1995/05/10 20:47:31 jtc Exp $";
00018 #endif
00019 
00020 #include <limits.h>
00021 #include "math.h"
00022 #include "math_private.h"
00023 
00024 #ifdef __STDC__
00025        int __ilogbf(float x)
00026 #else
00027        int __ilogbf(x)
00028        float x;
00029 #endif
00030 {
00031        int32_t hx,ix;
00032 
00033        GET_FLOAT_WORD(hx,x);
00034        hx &= 0x7fffffff;
00035        if(hx<0x00800000) {
00036            if(hx==0)
00037               return FP_ILOGB0;    /* ilogb(0) = FP_ILOGB0 */
00038            else                    /* subnormal x */
00039                for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
00040            return ix;
00041        }
00042        else if (hx<0x7f800000) return (hx>>23)-127;
00043        else if (FP_ILOGBNAN != INT_MAX) {
00044            /* ISO C99 requires ilogbf(+-Inf) == INT_MAX.  */
00045            if (hx==0x7f800000)
00046               return INT_MAX;
00047        }
00048        return FP_ILOGBNAN;
00049 }
00050 weak_alias (__ilogbf, ilogbf)