|
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 |
int64_t ix;
|
|
Packit Service |
82fcde |
int64_t k;
|
|
Packit Service |
82fcde |
EXTRACT_WORDS64(ix,x);
|
|
Packit Service |
82fcde |
k = (ix >> 52) & 0x7ff; /* extract exponent */
|
|
Packit Service |
82fcde |
if (__builtin_expect(k==0, 0)) { /* 0 or subnormal x */
|
|
Packit Service |
82fcde |
if ((ix & UINT64_C(0xfffffffffffff))==0) return x; /* +-0 */
|
|
Packit Service |
82fcde |
x *= two54;
|
|
Packit Service |
82fcde |
EXTRACT_WORDS64(ix,x);
|
|
Packit Service |
82fcde |
k = ((ix >> 52) & 0x7ff) - 54;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (__builtin_expect(k==0x7ff, 0)) return x+x; /* NaN or Inf */
|
|
Packit Service |
82fcde |
if (__builtin_expect(n< -50000, 0))
|
|
Packit Service |
82fcde |
return tiny*__copysign(tiny,x); /*underflow*/
|
|
Packit Service |
82fcde |
if (__builtin_expect(n> 50000 || k+n > 0x7fe, 0))
|
|
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 (__builtin_expect(k > 0, 1)) /* normal result */
|
|
Packit Service |
82fcde |
{INSERT_WORDS64(x,(ix&UINT64_C(0x800fffffffffffff))|(k<<52));
|
|
Packit Service |
82fcde |
return x;}
|
|
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 |
INSERT_WORDS64(x,(ix&INT64_C(0x800fffffffffffff))|(k<<52));
|
|
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
|