]>
Commit | Line | Data |
---|---|---|
f7eac6eb RM |
1 | /* @(#)s_logb.c 5.1 93/09/24 */ |
2 | /* | |
3 | * ==================================================== | |
4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | |
5 | * | |
6 | * Developed at SunPro, a Sun Microsystems, Inc. business. | |
7 | * Permission to use, copy, modify, and distribute this | |
cccda09f | 8 | * software is freely granted, provided that this notice |
f7eac6eb RM |
9 | * is preserved. |
10 | * ==================================================== | |
11 | */ | |
12 | ||
f7eac6eb RM |
13 | /* |
14 | * double logb(x) | |
15 | * IEEE 754 logb. Included to pass IEEE test suite. Not recommend. | |
16 | * Use ilogb instead. | |
17 | */ | |
18 | ||
1ed0291c RH |
19 | #include <math.h> |
20 | #include <math_private.h> | |
f7eac6eb | 21 | |
89c9aa49 AZ |
22 | double |
23 | __logb (double x) | |
f7eac6eb | 24 | { |
89c9aa49 AZ |
25 | int32_t lx, ix, rix; |
26 | ||
27 | EXTRACT_WORDS (ix, lx, x); | |
c5d5d574 | 28 | ix &= 0x7fffffff; /* high |x| */ |
89c9aa49 AZ |
29 | if ((ix | lx) == 0) |
30 | return -1.0 / fabs (x); | |
31 | if (ix >= 0x7ff00000) | |
32 | return x * x; | |
a1ffb40e | 33 | if (__glibc_unlikely ((rix = ix >> 20) == 0)) |
89c9aa49 AZ |
34 | { |
35 | /* POSIX specifies that denormal number is treated as | |
36 | though it were normalized. */ | |
25dbcb27 AS |
37 | int ma; |
38 | if (ix == 0) | |
39 | ma = __builtin_clz (lx) + 32; | |
40 | else | |
41 | ma = __builtin_clz (ix); | |
42 | rix -= ma - 12; | |
89c9aa49 AZ |
43 | } |
44 | return (double) (rix - 1023); | |
f7eac6eb RM |
45 | } |
46 | weak_alias (__logb, logb) | |
cccda09f | 47 | #ifdef NO_LONG_DOUBLE |
89c9aa49 | 48 | strong_alias (__logb, __logbl) weak_alias (__logb, logbl) |
cccda09f | 49 | #endif |