Path: blob/master/test/jdk/java/lang/StrictMath/PowTests.java
41149 views
/*1* Copyright (c) 2003, 2015, 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 813687426* @summary Tests for StrictMath.pow27* @author Joseph D. Darcy28*/2930/**31* The tests in ../Math/PowTests.java test properties that should32* hold for any pow implementation, including the FDLIBM-based one33* required for StrictMath.pow. Therefore, the test cases in34* ../Math/PowTests.java are run against both the Math and35* StrictMath versions of pow. The role of this test is to verify36* that the FDLIBM pow algorithm is being used by running golden37* file tests on values that may vary from one conforming pow38* implementation to another.39*/4041public class PowTests {42private PowTests(){}4344private static final double INFINITY = Double.POSITIVE_INFINITY;4546public static void main(String... args) {47int failures = 0;4849failures += testPow();5051if (failures > 0) {52System.err.println("Testing pow incurred "53+ failures + " failures.");54throw new RuntimeException();55}56}5758private static int testPow() {59int failures = 0;6061double [][] testCases = {62// Probe near decision points of the fdlibm algorithm6364{0x1.00000_0000_0001p1, // |x| > 1.065INFINITY, // infinity66INFINITY // 067},686970{0x1.fffffp-1, // |x| = 0.9999995231628418710x1.0p31, // 2^31720.0 // 073},7475{0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418760x1.0p31, // 2^31770.0 // 078},7980{-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418810x1.0p31, // 2^31820.0 // 083},8485{0x1.fffffp-1, // |x| = 0.9999995231628418860x1.0000000000001p31, // nextUp(2^31)870.0 // 088},8990{0x1.fffffp-1, // |x| = 0.9999995231628418910x1.0p31 + 1.0, // 2^31 + 1, odd integer920.0 // 093},9495{0x1.fffffp-1, // |x| = 0.9999995231628418960x1.0p31 + 2.0, // 2^31 + 2, even integer970.0 // 098},99100{0x1.ffffe_ffffffffp-1, // |x| < 0.99999952316284181010x1.0000000000001p31, // nextUp(2^31)1020.0 // 0103},104105{-0x1.ffffe_ffffffffp-1, // |x| < 0.99999952316284181060x1.0000000000001p31, // nextUp(2^31)107Double.NaN // 0108},109110{-0x1.ffffe_ffffffffp-1, // |x| < 0.99999952316284181110x1.0p31 + 1.0, // 2^31 + 1, odd integer112-0.0 // 0113},114115{-0x1.ffffe_ffffffffp-1, // |x| < 0.99999952316284181160x1.0p31 + 2.0, // 2^31 + 2, even integer1170.0 // 0118},119120{0x1.0000000000001p0, // nextUp(1)1210x1.0000000000001p31, // nextUp(2^31)1220x1.00000800002p0123},124125{0x1.0000000000001p0, // nextUp(1)126-0x1.0000000000001p31, // -nextUp(2^31)1270x1.fffff000004p-1128},129130{-0x1.0000000000001p0, // -nextUp(1)131-0x1.0000000000001p31, // -nextUp(2^31)132Double.NaN133},134135{-0x1.0000000000001p0, // -nextUp(1)1360x1.0p31 + 1.0, // 2^31 + 1, odd integer137-0x1.0000080000201p0138},139140{-0x1.0000000000001p0, // -nextUp(1)1410x1.0p31 + 2.0, // 2^31 + 2, even integer1420x1.0000080000202p0143},144145{0x1.00000_ffff_ffffp0,1460x1.00001_0000_0000p31,147INFINITY148},149150// Huge y, |y| > 0x1.00000_ffff_ffffp31 ~2**31 is a decision point151152// First y = 0x1.00001_0000_0000p31153{0x1.fffff_ffff_ffffp-1,1540x1.00001_0000_0000p31,1550x1.fffff7ffff9p-1156},157158{0x1.fffff_ffff_fffep-1,1590x1.00001_0000_0000p31,1600x1.ffffefffff4p-1161},162163{0x1.fffff_0000_0000p-1,1640x1.00001_0000_0000p31,1650.0166},167168// Cycle through decision points on x values169170{0x1.fffff_0000_0000p-1,1710x1.00001_0000_0000p31,1720.0173},174175{-0x1.fffff_0000_0000p-1,1760x1.00001_0000_0000p31,1770.0178},179180{0x1.ffffe_ffff_ffffp-1,1810x1.00001_0000_0000p31,1820.0183},184185{-0x1.ffffe_ffff_ffffp-1,1860x1.00001_0000_0000p31,1870.0188},189190{0x1.00000_ffff_ffffp0,1910x1.00001_0000_0000p31,192INFINITY193},194195196{0x1.00001_0000_0000p0,1970x1.00001_0000_0000p31,198INFINITY199},200201{-0x1.00000_ffff_ffffp0,2020x1.00001_0000_0000p31,203INFINITY204},205206207{-0x1.00001_0000_0000p0,2080x1.00001_0000_0000p31,209INFINITY210},211212// Now y = -0x1.00001_0000_0000p31213214{0x1.fffff_0000_0000p-1,215-0x1.00001_0000_0000p31,216INFINITY217},218219{-0x1.fffff_0000_0000p-1,2200x1.00001_0000_0000p31,2210.0222},223224{0x1.ffffe_ffff_ffffp-1,225-0x1.00001_0000_0000p31,226INFINITY227},228229{-0x1.ffffe_ffff_ffffp-1,230-0x1.00001_0000_0000p31,231INFINITY232},233234{0x1.00000_ffff_ffffp0,235-0x1.00001_0000_0000p31,2360.0237},238239240{0x1.00001_0000_0000p0,241-0x1.00001_0000_0000p31,2420.0243},244245{-0x1.00000_ffff_ffffp0,246-0x1.00001_0000_0000p31,2470.0248},249250251{-0x1.00001_0000_0000p0,252-0x1.00001_0000_0000p31,2530.0254},255256//-----------------------257258{0x1.ffffe_ffff_ffffp-1,259-0x1.00001_0000_0000p31,260INFINITY261},262263{0x1.00001_0000_0000p0,264-0x1.00001_0000_0000p31,2650.0266},267268269{0x1.0000000000002p0, // 1.00000000000000042700x1.f4add4p30, // 2.1E92710x1.00000fa56f1a6p0 // 1.0000009325877754272},273274// Verify no early overflow275{0x1.0000000000002p0, // 1.00000000000000042760x1.0642acp31, // 2.2E92770x1.000010642b465p0, // 1.0000009769967388278},279280// Verify proper overflow281{0x1.0000000000002p0, // 1.00000000000000042820x1.62e42fefa39fp60, // 1.59828858065033216E182830x1.ffffffffffd9fp1023, // 1.7976931348621944E308284},285286};287288for (double[] testCase: testCases)289failures += testPowCase(testCase[0], testCase[1], testCase[2]);290291return failures;292}293294private static int testPowCase(double input1, double input2, double expected) {295int failures = 0;296failures += Tests.test("StrictMath.pow(double)", input1, input2,297StrictMath.pow(input1, input2), expected);298return failures;299}300}301302303