1 /* 2 * ==================================================== 3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 4 * 5 * Developed at SunPro, a Sun Microsystems, Inc. business. 6 * Permission to use, copy, modify, and distribute this 7 * software is freely granted, provided that this notice 8 * is preserved. 9 * ==================================================== 10 */ 11 12 /* ilogb(double x) 13 * return the binary exponent of non-zero x 14 * ilogb(0) = FP_ILOGB0 15 * ilogb(NaN) = FP_ILOGBNAN (no signal is raised) 16 * ilogb(inf) = INT_MAX (no signal is raised) 17 */ 18 19 #include <limits.h> 20 21 #include "math.h" 22 #include "math_private.h" 23 24 int 25 ilogb(double x) 26 { 27 int32_t hx, ix, lx; 28 29 EXTRACT_WORDS(hx,lx,x); 30 hx &= 0x7fffffff; 31 if(hx<0x00100000) { 32 if((hx|lx)==0) 33 return FP_ILOGB0; 34 else 35 ix = subnormal_ilogb(hx, lx); 36 return ix; 37 } 38 else if (hx<0x7ff00000) return (hx>>20)-1023; 39 else if (hx>0x7ff00000 || lx!=0) return FP_ILOGBNAN; 40 else return INT_MAX; 41 } 42