Path: blob/master/test/jdk/java/lang/Math/Ieee754SpecialCaseTests.java
41149 views
/*1* Copyright (c) 2011, 2021, 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 824063226* @summary Test special cases of IEEE 754 recommended ops not otherwise tested27* @build Tests28* @build Ieee754SpecialCaseTests29* @run main Ieee754SpecialCaseTests30*/3132public class Ieee754SpecialCaseTests {33private Ieee754SpecialCaseTests() {throw new AssertionError("No instances for you.");}3435public static void main(String... args) {36int failures = 0;3738failures += testSpecialCos();39failures += testSpecialAcos();40failures += testSpecialAtan();41failures += testSpecialLog();4243if (failures > 0) {44System.err.printf("Testing special cases incurred %d failures.%n", failures);45throw new RuntimeException();46}47}48private static int testSpecialCos() {49int failures = 0;50double [][] testCases = {51{+0.0, 1.0},52{-0.0, 1.0},53};5455for(double[] testCase: testCases) {56failures += testCosCase(testCase[0], testCase[1]);57}5859return failures;60}6162private static int testCosCase(double input, double expected) {63int failures = 0;64failures += Tests.test("Math.cos", input, Math.cos(input), expected);65failures += Tests.test("StrictMath.cos", input, StrictMath.cos(input), expected);66return failures;67}6869private static int testSpecialAcos() {70int failures = 0;71double [][] testCases = {72{1.0, 0.0},73};7475for(double[] testCase: testCases) {76failures += testAcosCase(testCase[0], testCase[1]);77}7879return failures;80}8182private static int testAcosCase(double input, double expected) {83int failures = 0;84failures += Tests.test("Math.acos", input, Math.acos(input), expected);85failures += Tests.test("StrictMath.acos", input, StrictMath.acos(input), expected);86return failures;87}8889private static int testSpecialAtan() {90int failures = 0;91double [][] testCases = {92{Double.POSITIVE_INFINITY, +Math.PI/2.0},93{Double.NEGATIVE_INFINITY, -Math.PI/2.0},94};9596for(double[] testCase: testCases) {97failures += testAtanCase(testCase[0], testCase[1]);98}99100return failures;101}102103private static int testAtanCase(double input, double expected) {104int failures = 0;105failures += Tests.test("Math.atan", input, Math.atan(input), expected);106failures += Tests.test("StrictMath.atan", input, StrictMath.atan(input), expected);107return failures;108}109110private static int testSpecialLog() {111int failures = 0;112double [][] testCases = {113{1.0, +0.0},114};115116for(double[] testCase: testCases) {117failures += testLogCase(testCase[0], testCase[1]);118}119120return failures;121}122123private static int testLogCase(double input, double expected) {124int failures = 0;125failures += Tests.test("Math.log", input, Math.log(input), expected);126failures += Tests.test("StrictMath.log", input, StrictMath.log(input), expected);127return failures;128}129}130131132