author | malenkov |
Fri, 16 May 2014 15:51:57 +0400 | |
changeset 25088 | 8d4b058368f0 |
parent 24030 | 1b54fabeee2e |
permissions | -rw-r--r-- |
21420
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21420
diff
changeset
|
2 |
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
21420
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
4 |
* |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
8 |
* |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
13 |
* accompanied this code). |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
14 |
* |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
18 |
* |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
21 |
* questions. |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
22 |
*/ |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
23 |
|
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
24 |
/* |
24030 | 25 |
* @test |
21420
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
26 |
* @bug 8022780 |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
27 |
* @summary Test division of large values |
24030 | 28 |
* @run main/othervm -Xshare:off DivisionOverflow |
21420
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
29 |
* @author Dmitry Nadezhin |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
30 |
*/ |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
31 |
import java.math.BigInteger; |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
32 |
|
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
33 |
public class DivisionOverflow { |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
34 |
|
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
35 |
public static void main(String[] args) { |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
36 |
try { |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
37 |
BigInteger a = BigInteger.ONE.shiftLeft(2147483646); |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
38 |
BigInteger b = BigInteger.ONE.shiftLeft(1568); |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
39 |
BigInteger[] qr = a.divideAndRemainder(b); |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
40 |
BigInteger q = qr[0]; |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
41 |
BigInteger r = qr[1]; |
24030 | 42 |
if (!r.equals(BigInteger.ZERO)) { |
43 |
throw new RuntimeException("Incorrect signum() of remainder " + r.signum()); |
|
44 |
} |
|
45 |
if (q.bitLength() != 2147482079) { |
|
21420
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
46 |
throw new RuntimeException("Incorrect bitLength() of quotient " + q.bitLength()); |
24030 | 47 |
} |
21420
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
48 |
System.out.println("Division of large values passed without overflow."); |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
49 |
} catch (OutOfMemoryError e) { |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
50 |
// possible |
24030 | 51 |
System.err.println("DivisionOverflow skipped: OutOfMemoryError"); |
52 |
System.err.println("Run jtreg with -javaoption:-Xmx8g"); |
|
21420
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
53 |
} |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
54 |
} |
a56f40ab71ce
6910473: java.math.BigInteger.bitLength() may return negative "int" on large numbers
bpb
parents:
diff
changeset
|
55 |
} |