annotate libquadmath/math/logbq.c @ 158:494b0b89df80 default tip

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