|
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 |
/*
|
|
Packit Service |
82fcde |
* scalbn (double x, int n)
|
|
Packit Service |
82fcde |
* scalbn(x,n) returns x* 2**n computed by exponent
|
|
Packit Service |
82fcde |
* manipulation rather than by actually performing an
|
|
Packit Service |
82fcde |
* exponentiation or a multiplication.
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <math.h>
|
|
Packit Service |
82fcde |
#include <math_private.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static const double
|
|
Packit Service |
82fcde |
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
|
|
Packit Service |
82fcde |
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
|
|
Packit Service |
82fcde |
huge = 1.0e+300,
|
|
Packit Service |
82fcde |
tiny = 1.0e-300;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
double
|
|
Packit Service |
82fcde |
__scalbln (double x, long int n)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int32_t k, hx, lx;
|
|
Packit Service |
82fcde |
EXTRACT_WORDS (hx, lx, x);
|
|
Packit Service |
82fcde |
k = (hx & 0x7ff00000) >> 20; /* extract exponent */
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (k == 0)) /* 0 or subnormal x */
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if ((lx | (hx & 0x7fffffff)) == 0)
|
|
Packit Service |
82fcde |
return x; /* +-0 */
|
|
Packit Service |
82fcde |
x *= two54;
|
|
Packit Service |
82fcde |
GET_HIGH_WORD (hx, x);
|
|
Packit Service |
82fcde |
k = ((hx & 0x7ff00000) >> 20) - 54;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (k == 0x7ff))
|
|
Packit Service |
82fcde |
return x + x; /* NaN or Inf */
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (n < -50000))
|
|
Packit Service |
82fcde |
return tiny * __copysign (tiny, x); /*underflow*/
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (n > 50000 || k + n > 0x7fe))
|
|
Packit Service |
82fcde |
return huge * __copysign (huge, x); /* overflow */
|
|
Packit Service |
82fcde |
/* Now k and n are bounded we know that k = k+n does not
|
|
Packit Service |
82fcde |
overflow. */
|
|
Packit Service |
82fcde |
k = k + n;
|
|
Packit Service |
82fcde |
if (__glibc_likely (k > 0)) /* normal result */
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
SET_HIGH_WORD (x, (hx & 0x800fffff) | (k << 20)); return x;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (k <= -54)
|
|
Packit Service |
82fcde |
return tiny * __copysign (tiny, x); /*underflow*/
|
|
Packit Service |
82fcde |
k += 54; /* subnormal result */
|
|
Packit Service |
82fcde |
SET_HIGH_WORD (x, (hx & 0x800fffff) | (k << 20));
|
|
Packit Service |
82fcde |
return x * twom54;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
#ifdef NO_LONG_DOUBLE
|
|
Packit Service |
82fcde |
strong_alias (__scalbln, __scalblnl)
|
|
Packit Service |
82fcde |
#endif
|