base/math/s_ilogb.c

Go to the documentation of this file.
00001 /* @(#)s_ilogb.c 5.1 93/09/24 */ 00002 /* 00003 * ==================================================== 00004 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 00005 * 00006 * Developed at SunPro, a Sun Microsystems, Inc. business. 00007 * Permission to use, copy, modify, and distribute this 00008 * software is freely granted, provided that this notice 00009 * is preserved. 00010 * ==================================================== 00011 */ 00012 00013 #if defined(LIBM_SCCS) && !defined(lint) 00014 static char rcsid[] = "$NetBSD: s_ilogb.c,v 1.9 1995/05/10 20:47:28 jtc Exp $"; 00015 #endif 00016 00017 /* ilogb(double x) 00018 * return the binary exponent of non-zero x 00019 * ilogb(0) = 0x80000001 00020 * ilogb(inf/NaN) = 0x7fffffff (no signal is raised) 00021 */ 00022 00023 #include "math.h" 00024 #include "mathP.h" 00025 00026 #ifdef __STDC__ 00027 int ilogb(double x) 00028 #else 00029 int ilogb(x) 00030 double x; 00031 #endif 00032 { 00033 int32_t hx,lx,ix; 00034 00035 GET_HIGH_WORD(hx,x); 00036 hx &= 0x7fffffff; 00037 if(hx<0x00100000) { 00038 GET_LOW_WORD(lx,x); 00039 if((hx|lx)==0) 00040 return 0x80000001; /* ilogb(0) = 0x80000001 */ 00041 else /* subnormal x */ 00042 if(hx==0) { 00043 for (ix = -1043; lx>0; lx<<=1) ix -=1; 00044 } else { 00045 for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1; 00046 } 00047 return ix; 00048 } 00049 else if (hx<0x7ff00000) return (hx>>20)-1023; 00050 else return 0x7fffffff; 00051 }

Generated on Thu Nov 20 11:49:52 2008 for RTAI API by doxygen 1.3.8