test/jdk/java/math/BigInteger/LargeValueExceptions.java
author shade
Wed, 27 Mar 2019 11:35:41 +0100
changeset 54305 848859723503
parent 53327 620b31ed8807
permissions -rw-r--r--
8221401: java/math/BigInteger/LargeValueExceptions.java test should be disabled on 32-bit platforms Reviewed-by: stuefe, bpb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53327
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     1
/*
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     4
 *
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     8
 *
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    13
 * accompanied this code).
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    14
 *
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    18
 *
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    21
 * questions.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    22
 */
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    23
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    24
/*
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    25
 * @test
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    26
 * @bug 8200698
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    27
 * @summary Tests that exceptions are thrown for ops which would overflow
54305
848859723503 8221401: java/math/BigInteger/LargeValueExceptions.java test should be disabled on 32-bit platforms
shade
parents: 53327
diff changeset
    28
 * @requires (sun.arch.data.model == "64" & os.maxMemory >= 4g)
53327
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    29
 * @run testng/othervm -Xmx4g LargeValueExceptions
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    30
 */
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    31
import java.math.BigInteger;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    32
import static java.math.BigInteger.ONE;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    33
import org.testng.annotations.Test;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    34
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    35
//
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    36
// The intent of this test is to probe the boundaries between overflow and
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    37
// non-overflow, principally for multiplication and squaring, specifically
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    38
// the largest values which should not overflow and the smallest values which
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    39
// should. The transition values used are not necessarily at the exact
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    40
// boundaries but should be "close." Quite a few different values were used
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    41
// experimentally before settling on the ones in this test. For multiplication
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    42
// and squaring all cases are exercised: definite overflow and non-overflow
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    43
// which can be detected "up front," and "indefinite" overflow, i.e., overflow
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    44
// which cannot be detected up front so further calculations are required.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    45
//
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    46
// Testing negative values is unnecessary. For both multiplication and squaring
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    47
// the paths lead to the Toom-Cook algorithm where the signum is used only to
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    48
// determine the sign of the result and not in the intermediate calculations.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    49
// This is also true for exponentiation.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    50
//
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    51
// @Test annotations with optional element "enabled" set to "false" should
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    52
// succeed when "enabled" is set to "true" but they take too to run in the
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    53
// course of the typical regression test execution scenario.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    54
//
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    55
public class LargeValueExceptions {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    56
    // BigInteger.MAX_MAG_LENGTH
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    57
    private static final int MAX_INTS = 1 << 26;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    58
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    59
    // Number of bits corresponding to MAX_INTS
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    60
    private static final long MAX_BITS = (0xffffffffL & MAX_INTS) << 5L;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    61
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    62
    // Half BigInteger.MAX_MAG_LENGTH
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    63
    private static final int MAX_INTS_HALF = MAX_INTS / 2;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    64
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    65
    // --- squaring ---
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    66
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    67
    // Largest no overflow determined by examining data lengths alone.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    68
    @Test(enabled=false)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    69
    public void squareNoOverflow() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    70
        BigInteger x = ONE.shiftLeft(16*MAX_INTS - 1).subtract(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    71
        BigInteger y = x.multiply(x);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    72
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    73
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    74
    // Smallest no overflow determined by extra calculations.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    75
    @Test(enabled=false)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    76
    public void squareIndefiniteOverflowSuccess() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    77
        BigInteger x = ONE.shiftLeft(16*MAX_INTS - 1);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    78
        BigInteger y = x.multiply(x);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    79
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    80
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    81
    // Largest overflow detected by extra calculations.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    82
    @Test(expectedExceptions=ArithmeticException.class,enabled=false)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    83
    public void squareIndefiniteOverflowFailure() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    84
        BigInteger x = ONE.shiftLeft(16*MAX_INTS).subtract(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    85
        BigInteger y = x.multiply(x);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    86
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    87
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    88
    // Smallest overflow detected by examining data lengths alone.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    89
    @Test(expectedExceptions=ArithmeticException.class)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    90
    public void squareDefiniteOverflow() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    91
        BigInteger x = ONE.shiftLeft(16*MAX_INTS);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    92
        BigInteger y = x.multiply(x);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    93
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    94
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    95
    // --- multiplication ---
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    96
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    97
    // Largest no overflow determined by examining data lengths alone.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    98
    @Test(enabled=false)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
    99
    public void multiplyNoOverflow() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   100
        final int halfMaxBits = MAX_INTS_HALF << 5;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   101
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   102
        BigInteger x = ONE.shiftLeft(halfMaxBits).subtract(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   103
        BigInteger y = ONE.shiftLeft(halfMaxBits - 1).subtract(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   104
        BigInteger z = x.multiply(y);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   105
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   106
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   107
    // Smallest no overflow determined by extra calculations.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   108
    @Test(enabled=false)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   109
    public void multiplyIndefiniteOverflowSuccess() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   110
        BigInteger x = ONE.shiftLeft((int)(MAX_BITS/2) - 1);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   111
        long m = MAX_BITS - x.bitLength();
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   112
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   113
        BigInteger y = ONE.shiftLeft((int)(MAX_BITS/2) - 1);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   114
        long n = MAX_BITS - y.bitLength();
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   115
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   116
        if (m + n != MAX_BITS) {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   117
            throw new RuntimeException("Unexpected leading zero sum");
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   118
        }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   119
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   120
        BigInteger z = x.multiply(y);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   121
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   122
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   123
    // Largest overflow detected by extra calculations.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   124
    @Test(expectedExceptions=ArithmeticException.class,enabled=false)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   125
    public void multiplyIndefiniteOverflowFailure() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   126
        BigInteger x = ONE.shiftLeft((int)(MAX_BITS/2)).subtract(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   127
        long m = MAX_BITS - x.bitLength();
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   128
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   129
        BigInteger y = ONE.shiftLeft((int)(MAX_BITS/2)).subtract(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   130
        long n = MAX_BITS - y.bitLength();
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   131
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   132
        if (m + n != MAX_BITS) {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   133
            throw new RuntimeException("Unexpected leading zero sum");
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   134
        }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   135
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   136
        BigInteger z = x.multiply(y);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   137
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   138
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   139
    // Smallest overflow detected by examining data lengths alone.
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   140
    @Test(expectedExceptions=ArithmeticException.class)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   141
    public void multiplyDefiniteOverflow() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   142
        // multiply by 4 as MAX_INTS_HALF refers to ints
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   143
        byte[] xmag = new byte[4*MAX_INTS_HALF];
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   144
        xmag[0] = (byte)0xff;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   145
        BigInteger x = new BigInteger(1, xmag);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   146
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   147
        byte[] ymag = new byte[4*MAX_INTS_HALF + 1];
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   148
        ymag[0] = (byte)0xff;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   149
        BigInteger y = new BigInteger(1, ymag);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   150
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   151
        BigInteger z = x.multiply(y);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   152
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   153
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   154
    // --- exponentiation ---
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   155
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   156
    @Test(expectedExceptions=ArithmeticException.class)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   157
    public void powOverflow() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   158
        BigInteger.TEN.pow(Integer.MAX_VALUE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   159
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   160
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   161
    @Test(expectedExceptions=ArithmeticException.class)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   162
    public void powOverflow1() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   163
        int shift = 20;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   164
        int exponent = 1 << shift;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   165
        BigInteger x = ONE.shiftLeft((int)(MAX_BITS / exponent));
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   166
        BigInteger y = x.pow(exponent);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   167
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   168
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   169
    @Test(expectedExceptions=ArithmeticException.class)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   170
    public void powOverflow2() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   171
        int shift = 20;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   172
        int exponent = 1 << shift;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   173
        BigInteger x = ONE.shiftLeft((int)(MAX_BITS / exponent)).add(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   174
        BigInteger y = x.pow(exponent);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   175
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   176
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   177
    @Test(expectedExceptions=ArithmeticException.class,enabled=false)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   178
    public void powOverflow3() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   179
        int shift = 20;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   180
        int exponent = 1 << shift;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   181
        BigInteger x = ONE.shiftLeft((int)(MAX_BITS / exponent)).subtract(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   182
        BigInteger y = x.pow(exponent);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   183
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   184
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   185
    @Test(enabled=false)
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   186
    public void powOverflow4() {
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   187
        int shift = 20;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   188
        int exponent = 1 << shift;
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   189
        BigInteger x = ONE.shiftLeft((int)(MAX_BITS / exponent - 1)).add(ONE);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   190
        BigInteger y = x.pow(exponent);
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   191
    }
620b31ed8807 8200659: Improve BigDecimal support
bpb
parents:
diff changeset
   192
}