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 #include <sys/cdefs.h> 13 /* 14 * double logb(x) 15 * IEEE 754 logb. Included to pass IEEE test suite. Not recommend. 16 * Use ilogb instead. 17 */ 18 19 #include <float.h> 20 21 #include "math.h" 22 #include "math_private.h" 23 24 static const double 25 two54 = 1.80143985094819840000e+16; /* 43500000 00000000 */ 26 27 double 28 logb(double x) 29 { 30 int32_t lx,ix; 31 EXTRACT_WORDS(ix,lx,x); 32 ix &= 0x7fffffff; /* high |x| */ 33 if((ix|lx)==0) return -1.0/fabs(x); 34 if(ix>=0x7ff00000) return x*x; 35 if(ix<0x00100000) { 36 x *= two54; /* convert subnormal x to normal */ 37 GET_HIGH_WORD(ix,x); 38 ix &= 0x7fffffff; 39 return (double) ((ix>>20)-1023-54); 40 } else 41 return (double) ((ix>>20)-1023); 42 } 43 44 #if (LDBL_MANT_DIG == 53) 45 __weak_reference(logb, logbl); 46 #endif 47