< prev index next >

test/java/lang/StrictMath/CubeRootTests.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 21,35 **** * questions. */ /* * @test ! * @bug 4347132 * @summary Tests specifically for StrictMath.cbrt * @author Joseph D. Darcy */ /** * The tests in ../Math/CubeRootTests.java test properties that should * hold for any cube root implementation, including the FDLIBM-based * one required for StrictMath.cbrt. Therefore, the test cases in * ../Math/CubeRootTests.java are run against both the Math and --- 21,44 ---- * questions. */ /* * @test ! * @bug 4347132 8136799 ! * @key randomness ! * @library /lib/testlibrary/ ! * @build jdk.testlibrary.RandomFactory ! * @build Tests ! * @build FdlibmTranslit ! * @build CubeRootTests ! * @run main CubeRootTests * @summary Tests specifically for StrictMath.cbrt * @author Joseph D. Darcy */ + import jdk.testlibrary.RandomFactory; + /** * The tests in ../Math/CubeRootTests.java test properties that should * hold for any cube root implementation, including the FDLIBM-based * one required for StrictMath.cbrt. Therefore, the test cases in * ../Math/CubeRootTests.java are run against both the Math and
*** 40,49 **** --- 49,71 ---- */ public class CubeRootTests { private CubeRootTests(){} + public static void main(String [] argv) { + int failures = 0; + + failures += testCubeRoot(); + failures += testAgainstTranslit(); + + if (failures > 0) { + System.err.println("Testing the cube root incurred " + + failures + " failures."); + throw new RuntimeException(); + } + } + static int testCubeRootCase(double input, double expected) { int failures=0; double minus_input = -input; double minus_expected = -expected;
*** 456,473 **** failures+=testCubeRootCase(testCase[0], testCase[1]); return failures; } ! public static void main(String [] argv) { int failures = 0; ! failures += testCubeRoot(); ! if (failures > 0) { ! System.err.println("Testing the cube root incurred " ! + failures + " failures."); ! throw new RuntimeException(); } } } --- 478,523 ---- failures+=testCubeRootCase(testCase[0], testCase[1]); return failures; } + // Initialize shared random number generator + private static java.util.Random random = RandomFactory.getRandom(); ! /** ! * Test StrictMath.hypot against transliteration port of hypot. ! */ ! private static int testAgainstTranslit() { int failures = 0; + double x; ! // Test just above subnormal threshold... ! x = Double.MIN_NORMAL; ! failures += testRange(x, Math.ulp(x), 1000); ! ! // ... and just below subnormal threshold ... ! x = Math.nextDown(Double.MIN_NORMAL); ! failures += testRange(x, -Math.ulp(x), 1000); ! ! // ... and near zero. ! failures += testRange(0.0, Double.MIN_VALUE, 1000); ! ! x = Tests.createRandomDouble(random); ! // Make the increment twice the ulp value in case the random ! // value is near an exponent threshold. ! ! // Don't worry about x or y overflowing to infinity if their ! // exponent is MAX_EXPONENT. ! failures += testRange(x, 2.0 * Math.ulp(x), 1000); ! return failures; ! } ! ! private static int testRange(double start, double increment, int count) { ! int failures = 0; ! double x = start; ! for (int i = 0; i < count; i++, x += increment) { ! failures += testCubeRootCase(x, FdlibmTranslit.Cbrt.compute(x)); } + return failures; } }
< prev index next >