--- old/test/java/lang/StrictMath/CubeRootTests.java 2015-10-07 22:17:10.711093246 -0700 +++ new/test/java/lang/StrictMath/CubeRootTests.java 2015-10-07 22:17:10.547093239 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -23,11 +23,20 @@ /* * @test - * @bug 4347132 + * @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 @@ -42,6 +51,19 @@ 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; @@ -458,16 +480,44 @@ return failures; } + // Initialize shared random number generator + private static java.util.Random random = RandomFactory.getRandom(); - public static void main(String [] argv) { + /** + * Test StrictMath.hypot against transliteration port of hypot. + */ + private static int testAgainstTranslit() { int failures = 0; + double x; - failures += testCubeRoot(); + // 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); - if (failures > 0) { - System.err.println("Testing the cube root incurred " - + failures + " failures."); - throw new RuntimeException(); + 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; } }