~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/runtime/fdlibm/s_scalbn.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
/*
 
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.
 
6
 *
 
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.
 
12
 *
 
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).
 
18
 *
 
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.
 
22
 *
 
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
 
25
 * questions.
 
26
 */
 
27
 
 
28
/*
 
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.
 
33
 */
 
34
 
 
35
static partial class fdlibm
 
36
{
 
37
        static double scalbn(double x, int n)
 
38
        {
 
39
                const double
 
40
two54   =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
 
41
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
 
42
huge = 1.0e+300,
 
43
tiny = 1.0e-300;
 
44
 
 
45
        int  k,hx,lx;
 
46
        hx = __HI(x);
 
47
        lx = __LO(x);
 
48
        k = (hx&0x7ff00000)>>20;                /* extract exponent */
 
49
        if (k==0) {                             /* 0 or subnormal x */
 
50
            if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
 
51
            x *= two54;
 
52
            hx = __HI(x);
 
53
            k = ((hx&0x7ff00000)>>20) - 54;
 
54
            if (n< -50000) return tiny*x;       /*underflow*/
 
55
            }
 
56
        if (k==0x7ff) return x+x;               /* NaN or Inf */
 
57
        k = k+n;
 
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;}
 
61
        if (k <= -54) {
 
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*/
 
65
        }
 
66
        k += 54;                                /* subnormal result */
 
67
        x = __HI(x, (hx&unchecked((int)0x800fffff))|(k<<20));
 
68
        return x*twom54;
 
69
}
 
70
}