809N/A/*
2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
809N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
809N/A *
809N/A * This code is free software; you can redistribute it and/or modify it
809N/A * under the terms of the GNU General Public License version 2 only, as
809N/A * published by the Free Software Foundation.
809N/A *
809N/A * This code is distributed in the hope that it will be useful, but WITHOUT
809N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
809N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
809N/A * version 2 for more details (a copy is included in the LICENSE file that
809N/A * accompanied this code).
809N/A *
809N/A * You should have received a copy of the GNU General Public License version
809N/A * 2 along with this work; if not, write to the Free Software Foundation,
809N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
809N/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.
809N/A */
809N/A
809N/A/*
809N/A * @test
809N/A * @bug 4984872
809N/A * @summary Basic tests of toPlainString method
4014N/A * @run main ToPlainStringTests
4014N/A * @run main/othervm -XX:+AggressiveOpts ToPlainStringTests
809N/A * @author Joseph D. Darcy
809N/A */
809N/A
809N/Aimport java.math.*;
809N/A
809N/Apublic class ToPlainStringTests {
809N/A public static void main(String argv[]) {
809N/A String [][] testCases = {
809N/A {"0", "0"},
809N/A {"1", "1"},
809N/A {"10", "10"},
809N/A {"2e1", "20"},
809N/A {"3e2", "300"},
809N/A {"4e3", "4000"},
809N/A {"5e4", "50000"},
809N/A {"6e5", "600000"},
809N/A {"7e6", "7000000"},
809N/A {"8e7", "80000000"},
809N/A {"9e8", "900000000"},
809N/A {"1e9", "1000000000"},
809N/A
809N/A {".0", "0.0"},
809N/A {".1", "0.1"},
809N/A {".10", "0.10"},
809N/A {"1e-1", "0.1"},
809N/A {"1e-1", "0.1"},
809N/A {"2e-2", "0.02"},
809N/A {"3e-3", "0.003"},
809N/A {"4e-4", "0.0004"},
809N/A {"5e-5", "0.00005"},
809N/A {"6e-6", "0.000006"},
809N/A {"7e-7", "0.0000007"},
809N/A {"8e-8", "0.00000008"},
809N/A {"9e-9", "0.000000009"},
809N/A {"9000e-12", "0.000000009000"},
4014N/A
4014N/A {"9000e-22", "0.0000000000000000009000"},
4014N/A {"12345678901234567890", "12345678901234567890"},
4014N/A {"12345678901234567890e22", "123456789012345678900000000000000000000000"},
4014N/A {"12345678901234567890e-22", "0.0012345678901234567890"},
809N/A };
809N/A
809N/A int errors = 0;
809N/A for(String[] testCase: testCases) {
809N/A BigDecimal bd = new BigDecimal(testCase[0]);
809N/A String s;
809N/A
809N/A if (!(s=bd.toPlainString()).equals(testCase[1])) {
809N/A errors++;
809N/A System.err.println("Unexpected plain result ``" +
809N/A s + "'' from BigDecimal " +
809N/A bd);
809N/A }
4014N/A bd = new BigDecimal("-"+testCase[0]);
4014N/A if (bd.signum()!=0 && !(s=(bd.toPlainString())).equals("-"+testCase[1])) {
809N/A errors++;
809N/A System.err.println("Unexpected plain result ``" +
809N/A s + "'' from BigDecimal " +
809N/A bd);
809N/A }
809N/A }
809N/A
809N/A if(errors > 0)
809N/A throw new RuntimeException(errors + " errors during run.");
809N/A }
809N/A}