1*181254a7Smrg /* s_logbl.c -- long double version of s_logb.c.
2*181254a7Smrg * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
3*181254a7Smrg */
4*181254a7Smrg
5*181254a7Smrg /*
6*181254a7Smrg * ====================================================
7*181254a7Smrg * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8*181254a7Smrg *
9*181254a7Smrg * Developed at SunPro, a Sun Microsystems, Inc. business.
10*181254a7Smrg * Permission to use, copy, modify, and distribute this
11*181254a7Smrg * software is freely granted, provided that this notice
12*181254a7Smrg * is preserved.
13*181254a7Smrg * ====================================================
14*181254a7Smrg */
15*181254a7Smrg
16*181254a7Smrg #if defined(LIBM_SCCS) && !defined(lint)
17*181254a7Smrg static char rcsid[] = "NetBSD: ";
18*181254a7Smrg #endif
19*181254a7Smrg
20*181254a7Smrg /*
21*181254a7Smrg * long double logbq(x)
22*181254a7Smrg * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
23*181254a7Smrg * Use ilogb instead.
24*181254a7Smrg */
25*181254a7Smrg
26*181254a7Smrg #include "quadmath-imp.h"
27*181254a7Smrg
28*181254a7Smrg __float128
logbq(__float128 x)29*181254a7Smrg logbq (__float128 x)
30*181254a7Smrg {
31*181254a7Smrg int64_t lx, hx, ex;
32*181254a7Smrg
33*181254a7Smrg GET_FLT128_WORDS64 (hx, lx, x);
34*181254a7Smrg hx &= 0x7fffffffffffffffLL; /* high |x| */
35*181254a7Smrg if ((hx | lx) == 0)
36*181254a7Smrg return -1.0 / fabsq (x);
37*181254a7Smrg if (hx >= 0x7fff000000000000LL)
38*181254a7Smrg return x * x;
39*181254a7Smrg if ((ex = hx >> 48) == 0) /* IEEE 754 logb */
40*181254a7Smrg {
41*181254a7Smrg /* POSIX specifies that denormal number is treated as
42*181254a7Smrg though it were normalized. */
43*181254a7Smrg int ma;
44*181254a7Smrg if (hx == 0)
45*181254a7Smrg ma = __builtin_clzll (lx) + 64;
46*181254a7Smrg else
47*181254a7Smrg ma = __builtin_clzll (hx);
48*181254a7Smrg ex -= ma - 16;
49*181254a7Smrg }
50*181254a7Smrg return (__float128) (ex - 16383);
51*181254a7Smrg }
52