Fix for logb/logbf/logbl (bugs 13954/13955/13956)
[glibc.git] / sysdeps / ieee754 / ldbl-128 / s_logbl.c
blobcf6003e055ad9ce669bc0a7ba658b86080baa30f
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 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: $";
18 #endif
21 * long double logbl(x)
22 * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
23 * Use ilogb instead.
26 #include <math.h>
27 #include <math_private.h>
29 long double
30 __logbl (long double x)
32 int64_t lx, hx, ex;
34 GET_LDOUBLE_WORDS64 (hx, lx, x);
35 hx &= 0x7fffffffffffffffLL; /* high |x| */
36 if ((hx | lx) == 0)
37 return -1.0 / fabs (x);
38 if (hx >= 0x7fff000000000000LL)
39 return x * x;
40 if ((ex = hx >> 48) == 0) /* IEEE 754 logb */
42 /* POSIX specifies that denormal number is treated as
43 though it were normalized. */
44 int m1 = (hx == 0) ? 0 : __builtin_clzll (hx);
45 int m2 = (lx == 0) ? 0 : __builtin_clzll (lx);
46 int ma = (m1 == 0) ? m2 + 64 : m1;
47 return -16382.0 + (long double)(15 - ma);
49 return (long double) (ex - 16383);
52 weak_alias (__logbl, logbl)