4
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
5
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7
* This code is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 2 only, as
9
* published by the Free Software Foundation. Oracle designates this
10
* particular file as subject to the "Classpath" exception as provided
11
* by Oracle in the LICENSE file that accompanied this code.
13
* This code is distributed in the hope that it will be useful, but WITHOUT
14
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
* version 2 for more details (a copy is included in the LICENSE file that
17
* accompanied this code).
19
* You should have received a copy of the GNU General Public License version
20
* 2 along with this work; if not, write to the Free Software Foundation,
21
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24
* or visit www.oracle.com if you need additional information or have any
29
* scalbn (double x, int n)
30
* scalbn(x,n) returns x* 2**n computed by exponent
31
* manipulation rather than by actually performing an
32
* exponentiation or a multiplication.
35
static partial class fdlibm
37
static double scalbn(double x, int n)
40
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
41
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
48
k = (hx&0x7ff00000)>>20; /* extract exponent */
49
if (k==0) { /* 0 or subnormal x */
50
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
53
k = ((hx&0x7ff00000)>>20) - 54;
54
if (n< -50000) return tiny*x; /*underflow*/
56
if (k==0x7ff) return x+x; /* NaN or Inf */
58
if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */
59
if (k > 0) /* normal result */
60
{x = __HI(x, (hx&unchecked((int)0x800fffff))|(k<<20)); return x;}
62
if (n > 50000) /* in case integer overflow in n+k */
63
return huge*copysign(huge,x); /*overflow*/
64
else return tiny*copysign(tiny,x); /*underflow*/
66
k += 54; /* subnormal result */
67
x = __HI(x, (hx&unchecked((int)0x800fffff))|(k<<20));