Blame sysdeps/ieee754/dbl-64/s_logb.c
|
Packit |
6c4009 |
/* @(#)s_logb.c 5.1 93/09/24 */
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
6c4009 |
* software is freely granted, provided that this notice
|
|
Packit |
6c4009 |
* is preserved.
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* double logb(x)
|
|
Packit |
6c4009 |
* IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
|
|
Packit |
6c4009 |
* Use ilogb instead.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
#include <libm-alias-double.h>
|
|
Packit |
6c4009 |
#include <fix-int-fp-convert-zero.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
double
|
|
Packit |
6c4009 |
__logb (double x)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int32_t lx, ix, rix;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
EXTRACT_WORDS (ix, lx, x);
|
|
Packit |
6c4009 |
ix &= 0x7fffffff; /* high |x| */
|
|
Packit |
6c4009 |
if ((ix | lx) == 0)
|
|
Packit |
6c4009 |
return -1.0 / fabs (x);
|
|
Packit |
6c4009 |
if (ix >= 0x7ff00000)
|
|
Packit |
6c4009 |
return x * x;
|
|
Packit |
6c4009 |
if (__glibc_unlikely ((rix = ix >> 20) == 0))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* POSIX specifies that denormal number is treated as
|
|
Packit |
6c4009 |
though it were normalized. */
|
|
Packit |
6c4009 |
int ma;
|
|
Packit |
6c4009 |
if (ix == 0)
|
|
Packit |
6c4009 |
ma = __builtin_clz (lx) + 32;
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
ma = __builtin_clz (ix);
|
|
Packit |
6c4009 |
rix -= ma - 12;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (FIX_INT_FP_CONVERT_ZERO && rix == 1023)
|
|
Packit |
6c4009 |
return 0.0;
|
|
Packit |
6c4009 |
return (double) (rix - 1023);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#ifndef __logb
|
|
Packit |
6c4009 |
libm_alias_double (__logb, logb)
|
|
Packit |
6c4009 |
#endif
|