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 | */ |
4 | |
5 | /* |
6 | * ==================================================== |
7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
8 | * |
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 | * ==================================================== |
14 | */ |
15 | |
16 | /* |
17 | * long double logbl(x) |
18 | * IEEE 754 logb. Included to pass IEEE test suite. Not recommend. |
19 | * Use ilogb instead. |
20 | */ |
21 | |
22 | #include "quadmath-imp.h" |
23 | |
24 | __float128 |
25 | logbq (__float128 x) |
26 | { |
27 | int64_t lx, hx, ex; |
28 | |
29 | GET_FLT128_WORDS64 (hx, lx, x); |
30 | hx &= 0x7fffffffffffffffLL; /* high |x| */ |
31 | if ((hx | lx) == 0) |
32 | return -1.0 / fabsq (x); |
33 | if (hx >= 0x7fff000000000000LL) |
34 | return x * x; |
35 | if ((ex = hx >> 48) == 0) /* IEEE 754 logb */ |
36 | { |
37 | /* POSIX specifies that denormal number is treated as |
38 | though it were normalized. */ |
39 | int ma; |
40 | if (hx == 0) |
41 | ma = __builtin_clzll (lx) + 64; |
42 | else |
43 | ma = __builtin_clzll (hx); |
44 | ex -= ma - 16; |
45 | } |
46 | return (__float128) (ex - 16383); |
47 | } |
48 | |