Path: blob/master/src/java.base/share/native/libfdlibm/s_scalbn.c
41149 views
/*1* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* scalbn (double x, int n)27* scalbn(x,n) returns x* 2**n computed by exponent28* manipulation rather than by actually performing an29* exponentiation or a multiplication.30*/3132#include "fdlibm.h"3334#ifdef __STDC__35static const double36#else37static double38#endif39two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */40twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */41huge = 1.0e+300,42tiny = 1.0e-300;4344#ifdef __STDC__45double scalbn (double x, int n)46#else47double scalbn (x,n)48double x; int n;49#endif50{51int k,hx,lx;52hx = __HI(x);53lx = __LO(x);54k = (hx&0x7ff00000)>>20; /* extract exponent */55if (k==0) { /* 0 or subnormal x */56if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */57x *= two54;58hx = __HI(x);59k = ((hx&0x7ff00000)>>20) - 54;60if (n< -50000) return tiny*x; /*underflow*/61}62if (k==0x7ff) return x+x; /* NaN or Inf */63k = k+n;64if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */65if (k > 0) /* normal result */66{__HI(x) = (hx&0x800fffff)|(k<<20); return x;}67if (k <= -54) {68if (n > 50000) /* in case integer overflow in n+k */69return huge*copysign(huge,x); /*overflow*/70else return tiny*copysign(tiny,x); /*underflow*/71}72k += 54; /* subnormal result */73__HI(x) = (hx&0x800fffff)|(k<<20);74return x*twom54;75}767778