Fix for logb/logbf/logbl (bugs 13954/13955/13956)
[glibc.git] / sysdeps / ieee754 / dbl-64 / s_logb.c
blobbaa35e14d85dc6733e03e3fd26dc25e4c6677d23
1 /* @(#)s_logb.c 5.1 93/09/24 */
2 /*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
9 * is preserved.
10 * ====================================================
14 * double logb(x)
15 * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
16 * Use ilogb instead.
19 #include <math.h>
20 #include <math_private.h>
22 double
23 __logb (double x)
25 int32_t lx, ix, rix;
27 EXTRACT_WORDS (ix, lx, x);
28 ix &= 0x7fffffff; /* high |x| */
29 if ((ix | lx) == 0)
30 return -1.0 / fabs (x);
31 if (ix >= 0x7ff00000)
32 return x * x;
33 if (__builtin_expect ((rix = ix >> 20) == 0, 0))
35 /* POSIX specifies that denormal number is treated as
36 though it were normalized. */
37 int m1 = (ix == 0) ? 0 : __builtin_clz (ix);
38 int m2 = (lx == 0) ? 0 : __builtin_clz (lx);
39 int ma = (m1 == 0) ? m2 + 32 : m1;
40 return -1022.0 + (double)(11 - ma);
42 return (double) (rix - 1023);
44 weak_alias (__logb, logb)
45 #ifdef NO_LONG_DOUBLE
46 strong_alias (__logb, __logbl) weak_alias (__logb, logbl)
47 #endif