Back to index

glibc  2.9
s_ilogbl.c
Go to the documentation of this file.
00001 /* s_ilogbl.c -- long double version of s_ilogb.c.
00002  * Conversion to long double by Ulrich Drepper,
00003  * Cygnus Support, drepper@cygnus.com.
00004  */
00005 
00006 /*
00007  * ====================================================
00008  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00009  *
00010  * Developed at SunPro, a Sun Microsystems, Inc. business.
00011  * Permission to use, copy, modify, and distribute this
00012  * software is freely granted, provided that this notice
00013  * is preserved.
00014  * ====================================================
00015  */
00016 
00017 #if defined(LIBM_SCCS) && !defined(lint)
00018 static char rcsid[] = "$NetBSD: $";
00019 #endif
00020 
00021 /* ilogbl(long double x)
00022  * return the binary exponent of non-zero x
00023  * ilogbl(0) = FP_ILOGB0
00024  * ilogbl(NaN) = FP_ILOGBNAN (no signal is raised)
00025  * ilogbl(+-Inf) = INT_MAX (no signal is raised)
00026  */
00027 
00028 #include <limits.h>
00029 #include "math.h"
00030 #include "math_private.h"
00031 
00032 #ifdef __STDC__
00033        int __ilogbl(long double x)
00034 #else
00035        int __ilogbl(x)
00036        long double x;
00037 #endif
00038 {
00039        int32_t es,hx,lx,ix;
00040 
00041        GET_LDOUBLE_EXP(es,x);
00042        es &= 0x7fff;
00043        if(es==0) {
00044            GET_LDOUBLE_WORDS(es,hx,lx,x);
00045            if((hx|lx)==0)
00046               return FP_ILOGB0;    /* ilogbl(0) = FP_ILOGB0 */
00047            else                    /* subnormal x */
00048               if(hx==0) {
00049                   for (ix = -16415; lx>0; lx<<=1) ix -=1;
00050               } else {
00051                   for (ix = -16383; hx>0; hx<<=1) ix -=1;
00052               }
00053            return ix;
00054        }
00055        else if (es<0x7fff) return es-0x3fff;
00056        else if (FP_ILOGBNAN != INT_MAX)
00057        {
00058            GET_LDOUBLE_WORDS(es,hx,lx,x);
00059            if (((hx & 0x7fffffff)|lx) == 0)
00060              /* ISO C99 requires ilogbl(+-Inf) == INT_MAX.  */
00061              return INT_MAX;
00062        }
00063        return FP_ILOGBNAN;
00064 }
00065 weak_alias (__ilogbl, ilogbl)