Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/math/BigInteger/DivisionOverflow.java
38811 views
/*1* Copyright (c) 2011, 2013, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @ test25* @bug 802278026* @summary Test division of large values27* @author Dmitry Nadezhin28*/29import java.math.BigInteger;3031public class DivisionOverflow {3233public static void main(String[] args) {34try {35BigInteger a = BigInteger.ONE.shiftLeft(2147483646);36BigInteger b = BigInteger.ONE.shiftLeft(1568);37BigInteger[] qr = a.divideAndRemainder(b);38BigInteger q = qr[0];39BigInteger r = qr[1];40if (!r.equals(BigInteger.ZERO))41throw new RuntimeException("Incorrect singum() of remainder " + r.signum());42if (q.bitLength() != 2147482079)43throw new RuntimeException("Incorrect bitLength() of quotient " + q.bitLength());44System.out.println("Division of large values passed without overflow.");45} catch (OutOfMemoryError e) {46// possible47System.out.println("OutOfMemoryError");48}49}50}515253