1 /* 2 * From: @(#)s_ilogb.c 5.1 93/09/24 3 * ==================================================== 4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 * 6 * Developed at SunPro, a Sun Microsystems, Inc. business. 7 * Permission to use, copy, modify, and distribute this 8 * software is freely granted, provided that this notice 9 * is preserved. 10 * ==================================================== 11 */ 12 13 14 long double logbl(long double x)15logbl(long double x) 16 { 17 union IEEEl2bits u; 18 uint64_t m; 19 int b; 20 21 u.e = x; 22 if (u.bits.exp == 0) { 23 if ((u.bits.manl | u.bits.manh) == 0) { /* x == 0 */ 24 u.bits.sign = 1; 25 return (1.0L / u.e); 26 } 27 /* denormalized */ 28 #ifdef LDBL_MANL_SIZE 29 if (u.bits.manh == 0) { 30 m = 1llu << (LDBL_MANL_SIZE - 1); 31 for (b = LDBL_MANH_SIZE; !(u.bits.manl & m); m >>= 1) 32 b++; 33 } else 34 #endif 35 { 36 m = 1llu << (LDBL_MANH_SIZE - 1); 37 for (b = 0; !(u.bits.manh & m); m >>= 1) 38 b++; 39 } 40 #ifdef LDBL_IMPLICIT_NBIT 41 b++; 42 #endif 43 return ((long double)(LDBL_MIN_EXP - b - 1)); 44 } 45 if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1) /* normal */ 46 return ((long double)(u.bits.exp - LDBL_MAX_EXP + 1)); 47 else /* +/- inf or nan */ 48 return (x * x); 49 } 50