|
Packit Service |
82fcde |
/* s_ilogbl.c -- long double version of s_ilogb.c.
|
|
Packit Service |
82fcde |
* Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/*
|
|
Packit Service |
82fcde |
* ====================================================
|
|
Packit Service |
82fcde |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit Service |
82fcde |
*
|
|
Packit Service |
82fcde |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit Service |
82fcde |
* Permission to use, copy, modify, and distribute this
|
|
Packit Service |
82fcde |
* software is freely granted, provided that this notice
|
|
Packit Service |
82fcde |
* is preserved.
|
|
Packit Service |
82fcde |
* ====================================================
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#if defined(LIBM_SCCS) && !defined(lint)
|
|
Packit Service |
82fcde |
static char rcsid[] = "$NetBSD: $";
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* ilogbl(long double x)
|
|
Packit Service |
82fcde |
* return the binary exponent of non-zero x
|
|
Packit Service |
82fcde |
* ilogbl(0) = FP_ILOGB0
|
|
Packit Service |
82fcde |
* ilogbl(NaN) = FP_ILOGBNAN (no signal is raised)
|
|
Packit Service |
82fcde |
* ilogbl(+-Inf) = INT_MAX (no signal is raised)
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <limits.h>
|
|
Packit Service |
82fcde |
#include <math.h>
|
|
Packit Service |
82fcde |
#include <math_private.h>
|
|
Packit Service |
82fcde |
#include <math_ldbl_opt.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int __ieee754_ilogbl(long double x)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int64_t hx, hxs;
|
|
Packit Service |
82fcde |
int ix;
|
|
Packit Service |
82fcde |
double xhi, xlo;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
ldbl_unpack (x, &xhi, &xlo;;
|
|
Packit Service |
82fcde |
EXTRACT_WORDS64 (hx, xhi);
|
|
Packit Service |
82fcde |
hxs = hx;
|
|
Packit Service |
82fcde |
hx &= 0x7fffffffffffffffLL;
|
|
Packit Service |
82fcde |
if(hx <= 0x0010000000000000LL) {
|
|
Packit Service |
82fcde |
if(hx==0)
|
|
Packit Service |
82fcde |
return FP_ILOGB0; /* ilogbl(0) = FP_ILOGB0 */
|
|
Packit Service |
82fcde |
else /* subnormal x */
|
|
Packit Service |
82fcde |
for (ix = -1022, hx<<=11; hx>0; hx<<=1) ix -=1;
|
|
Packit Service |
82fcde |
return ix;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else if (hx < 0x7ff0000000000000LL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int hexp = (hx >> 52) - 0x3ff;
|
|
Packit Service |
82fcde |
/* If the high part is a power of 2, and the low part is
|
|
Packit Service |
82fcde |
nonzero with the opposite sign, the low part affects
|
|
Packit Service |
82fcde |
the exponent. */
|
|
Packit Service |
82fcde |
if ((hx & 0x000fffffffffffffLL) == 0)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int64_t lx;
|
|
Packit Service |
82fcde |
EXTRACT_WORDS64 (lx, xlo);
|
|
Packit Service |
82fcde |
if ((hxs ^ lx) < 0 && (lx & 0x7fffffffffffffffLL) != 0)
|
|
Packit Service |
82fcde |
hexp--;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
return hexp;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else if (FP_ILOGBNAN != INT_MAX) {
|
|
Packit Service |
82fcde |
/* ISO C99 requires ilogbl(+-Inf) == INT_MAX. */
|
|
Packit Service |
82fcde |
if (hx==0x7ff0000000000000LL)
|
|
Packit Service |
82fcde |
return INT_MAX;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
return FP_ILOGBNAN;
|
|
Packit Service |
82fcde |
}
|