1 /* s_logbl.c -- long double version of s_logb.c.
2  */
3 
4 /*
5  * ====================================================
6  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7  *
8  * Developed at SunPro, a Sun Microsystems, Inc. business.
9  * Permission to use, copy, modify, and distribute this
10  * software is freely granted, provided that this notice
11  * is preserved.
12  * ====================================================
13  */
14 
15 /*
16  * long double logbl(x)
17  * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
18  * Use ilogb instead.
19  */
20 
21 #include <math.h>
22 #include <math_private.h>
23 #include <math_ldbl_opt.h>
24 #include <fix-int-fp-convert-zero.h>
25 
26 long double
__logbl(long double x)27 __logbl (long double x)
28 {
29   int64_t hx, hxs, rhx;
30   double xhi, xlo;
31 
32   ldbl_unpack (x, &xhi, &xlo);
33   EXTRACT_WORDS64 (hx, xhi);
34   hxs = hx;
35   hx &= 0x7fffffffffffffffLL;	/* high |x| */
36   if (hx == 0)
37     return -1.0 / fabs (x);
38   if (hx >= 0x7ff0000000000000LL)
39     return x * x;
40   if (__glibc_unlikely ((rhx = hx >> 52) == 0))
41     {
42       /* POSIX specifies that denormal number is treated as
43          though it were normalized.  */
44       rhx -= __builtin_clzll (hx) - 12;
45     }
46   else if ((hx & 0x000fffffffffffffLL) == 0)
47     {
48       /* If the high part is a power of 2, and the low part is nonzero
49 	 with the opposite sign, the low part affects the
50 	 exponent.  */
51       int64_t lx;
52       EXTRACT_WORDS64 (lx, xlo);
53       if ((hxs ^ lx) < 0 && (lx & 0x7fffffffffffffffLL) != 0)
54 	rhx--;
55     }
56   if (FIX_INT_FP_CONVERT_ZERO && rhx == 1023)
57     return 0.0L;
58   return (long double) (rhx - 1023);
59 }
60 #ifndef __logbl
61 long_double_symbol (libm, __logbl, logbl);
62 #endif
63