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