1247N/A/*
2362N/A * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
1247N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1247N/A *
1247N/A * This code is free software; you can redistribute it and/or modify it
1247N/A * under the terms of the GNU General Public License version 2 only, as
1247N/A * published by the Free Software Foundation.
1247N/A *
1247N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1247N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1247N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1247N/A * version 2 for more details (a copy is included in the LICENSE file that
1247N/A * accompanied this code).
1247N/A *
1247N/A * You should have received a copy of the GNU General Public License version
1247N/A * 2 along with this work; if not, write to the Free Software Foundation,
1247N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1247N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1247N/A */
1247N/A
1247N/A/*
1247N/A * @test
1307N/A * @bug 6850606
1247N/A * @summary Test BigDecimal.multiply(BigDecimal)
1247N/A * @author xlu
1247N/A */
1247N/A
1247N/Aimport java.math.*;
1247N/Aimport static java.math.BigDecimal.*;
1247N/A
1247N/Apublic class MultiplyTests {
1247N/A
1247N/A private static int multiplyTests() {
1247N/A int failures = 0;
1247N/A
1247N/A BigDecimal[] bd1 = {
1247N/A new BigDecimal("123456789"),
1247N/A new BigDecimal("1234567898"),
1247N/A new BigDecimal("12345678987")
1247N/A };
1247N/A
1247N/A BigDecimal[] bd2 = {
1247N/A new BigDecimal("987654321"),
1247N/A new BigDecimal("8987654321"),
1247N/A new BigDecimal("78987654321")
1247N/A };
1247N/A
1247N/A // Two dimensonal array recording bd1[i] * bd2[j] &
1247N/A // 0 <= i <= 2 && 0 <= j <= 2;
1247N/A BigDecimal[][] expectedResults = {
1247N/A {new BigDecimal("121932631112635269"),
1247N/A new BigDecimal("1109586943112635269"),
1247N/A new BigDecimal("9751562173112635269")
1247N/A },
1247N/A { new BigDecimal("1219326319027587258"),
1247N/A new BigDecimal("11095869503027587258"),
1247N/A new BigDecimal("97515622363027587258")
1247N/A },
1247N/A { new BigDecimal("12193263197189452827"),
1247N/A new BigDecimal("110958695093189452827"),
1247N/A new BigDecimal("975156224183189452827")
1247N/A }
1247N/A };
1247N/A
1247N/A for (int i = 0; i < bd1.length; i++) {
1247N/A for (int j = 0; j < bd2.length; j++) {
1247N/A if (!bd1[i].multiply(bd2[j]).equals(expectedResults[i][j])) {
1247N/A failures++;
1247N/A }
1247N/A }
1247N/A }
1307N/A
1307N/A BigDecimal x = BigDecimal.valueOf(8L, 1);
1307N/A BigDecimal xPower = BigDecimal.valueOf(-1L);
1307N/A try {
1307N/A for (int i = 0; i < 100; i++) {
1307N/A xPower = xPower.multiply(x);
1307N/A }
1307N/A } catch (Exception ex) {
1307N/A failures++;
1307N/A }
1247N/A return failures;
1247N/A }
1247N/A
1247N/A public static void main(String[] args) {
1247N/A int failures = 0;
1247N/A
1247N/A failures += multiplyTests();
1247N/A
1247N/A if (failures > 0) {
1247N/A throw new RuntimeException("Incurred " + failures +
1247N/A " failures while testing multiply.");
1247N/A }
1247N/A }
1247N/A}