initial commit
[glibc.git] / sysdeps / ieee754 / ldbl-128 / s_logbl.c
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 #if defined(LIBM_SCCS) && !defined(lint)
16 static char rcsid[] = "$NetBSD: $";
17 #endif
18
19 /*
20 * long double logbl(x)
21 * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
22 * Use ilogb instead.
23 */
24
25 #include <math.h>
26 #include <math_private.h>
27 #include <libm-alias-ldouble.h>
28
29 _Float128
30 __logbl (_Float128 x)
31 {
32 int64_t lx, hx, ex;
33
34 GET_LDOUBLE_WORDS64 (hx, lx, x);
35 hx &= 0x7fffffffffffffffLL; /* high |x| */
36 if ((hx | lx) == 0)
37 return -1.0 / fabsl (x);
38 if (hx >= 0x7fff000000000000LL)
39 return x * x;
40 if ((ex = hx >> 48) == 0) /* IEEE 754 logb */
41 {
42 /* POSIX specifies that denormal number is treated as
43 though it were normalized. */
44 int ma;
45 if (hx == 0)
46 ma = __builtin_clzll (lx) + 64;
47 else
48 ma = __builtin_clzll (hx);
49 ex -= ma - 16;
50 }
51 return (_Float128) (ex - 16383);
52 }
53
54 libm_alias_ldouble (__logb, logb)