10
10
* ====================================================
13
#if defined(LIBM_SCCS) && !defined(lint)
14
static char rcsid[] = "$NetBSD: s_logb.c,v 1.8 1995/05/10 20:47:50 jtc Exp $";
19
15
* IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
20
16
* Use ilogb instead.
24
#include "math_private.h"
20
#include <math_private.h>
27
double __logb(double x)
34
EXTRACT_WORDS(ix,lx,x);
35
ix &= 0x7fffffff; /* high |x| */
36
if((ix|lx)==0) return -1.0/fabs(x);
37
if(ix>=0x7ff00000) return x*x;
38
if((ix>>=20)==0) /* IEEE 754 logb */
41
return (double) (ix-1023);
28
EXTRACT_WORDS (ix, lx, x);
29
ix &= 0x7fffffff; /* high |x| */
31
return -1.0 / fabs (x);
34
if (__builtin_expect ((rix = ix >> 20) == 0, 0))
36
/* POSIX specifies that denormal number is treated as
37
though it were normalized. */
40
ma = __builtin_clz (lx) + 32;
42
ma = __builtin_clz (ix);
45
ret = (double) (rix - 1023);
46
/* The test is to avoid logb_downward (0.0) == -0.0. */
47
return ret == -0.0 ? 0.0 : ret;
43
49
weak_alias (__logb, logb)
44
50
#ifdef NO_LONG_DOUBLE
45
strong_alias (__logb, __logbl)
46
weak_alias (__logb, logbl)
51
strong_alias (__logb, __logbl) weak_alias (__logb, logbl)