1 /* 2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8136874 27 * @summary Tests for StrictMath.pow 28 * @author Joseph D. Darcy 29 */ 30 package test.java.lang.StrictMath; 31 32 import org.testng.annotations.Test; 33 34 /** 35 * The tests in ../Math/PowTests.java test properties that should hold for any pow implementation, 36 * including the FDLIBM-based one required for StrictMath.pow. Therefore, the test cases in 37 * ../Math/PowTests.java are run against both the Math and StrictMath versions of pow. The role of 38 * this test is to verify that the FDLIBM pow algorithm is being used by running golden file tests 39 * on values that may vary from one conforming pow implementation to another. 40 */ 41 42 public class PowTests { 43 PowTests()44 private PowTests() { 45 } 46 47 private static final double INFINITY = Double.POSITIVE_INFINITY; 48 49 @Test testPow()50 public void testPow() { 51 double[][] testCases = { 52 // Probe near decision points of the fdlibm algorithm 53 54 {0x1.00000_0000_0001p1, // |x| > 1.0 55 INFINITY, // infinity 56 INFINITY // 0 57 }, 58 59 {0x1.fffffp-1, // |x| = 0.9999995231628418 60 0x1.0p31, // 2^31 61 0.0 // 0 62 }, 63 64 {0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418 65 0x1.0p31, // 2^31 66 0.0 // 0 67 }, 68 69 {-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418 70 0x1.0p31, // 2^31 71 0.0 // 0 72 }, 73 74 {0x1.fffffp-1, // |x| = 0.9999995231628418 75 0x1.0000000000001p31, // nextUp(2^31) 76 0.0 // 0 77 }, 78 79 {0x1.fffffp-1, // |x| = 0.9999995231628418 80 0x1.0p31 + 1.0, // 2^31 + 1, odd integer 81 0.0 // 0 82 }, 83 84 {0x1.fffffp-1, // |x| = 0.9999995231628418 85 0x1.0p31 + 2.0, // 2^31 + 2, even integer 86 0.0 // 0 87 }, 88 89 {0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418 90 0x1.0000000000001p31, // nextUp(2^31) 91 0.0 // 0 92 }, 93 94 {-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418 95 0x1.0000000000001p31, // nextUp(2^31) 96 Double.NaN // 0 97 }, 98 99 {-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418 100 0x1.0p31 + 1.0, // 2^31 + 1, odd integer 101 -0.0 // 0 102 }, 103 104 {-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418 105 0x1.0p31 + 2.0, // 2^31 + 2, even integer 106 0.0 // 0 107 }, 108 109 {0x1.0000000000001p0, // nextUp(1) 110 0x1.0000000000001p31, // nextUp(2^31) 111 0x1.00000800002p0 112 }, 113 114 {0x1.0000000000001p0, // nextUp(1) 115 -0x1.0000000000001p31, // -nextUp(2^31) 116 0x1.fffff000004p-1 117 }, 118 119 {-0x1.0000000000001p0, // -nextUp(1) 120 -0x1.0000000000001p31, // -nextUp(2^31) 121 Double.NaN 122 }, 123 124 {-0x1.0000000000001p0, // -nextUp(1) 125 0x1.0p31 + 1.0, // 2^31 + 1, odd integer 126 -0x1.0000080000201p0 127 }, 128 129 {-0x1.0000000000001p0, // -nextUp(1) 130 0x1.0p31 + 2.0, // 2^31 + 2, even integer 131 0x1.0000080000202p0 132 }, 133 134 {0x1.00000_ffff_ffffp0, 135 0x1.00001_0000_0000p31, 136 INFINITY 137 }, 138 139 // Huge y, |y| > 0x1.00000_ffff_ffffp31 ~2**31 is a decision point 140 141 // First y = 0x1.00001_0000_0000p31 142 {0x1.fffff_ffff_ffffp-1, 143 0x1.00001_0000_0000p31, 144 0x1.fffff7ffff9p-1 145 }, 146 147 {0x1.fffff_ffff_fffep-1, 148 0x1.00001_0000_0000p31, 149 0x1.ffffefffff4p-1 150 }, 151 152 {0x1.fffff_0000_0000p-1, 153 0x1.00001_0000_0000p31, 154 0.0 155 }, 156 157 // Cycle through decision points on x values 158 159 {0x1.fffff_0000_0000p-1, 160 0x1.00001_0000_0000p31, 161 0.0 162 }, 163 164 {-0x1.fffff_0000_0000p-1, 165 0x1.00001_0000_0000p31, 166 0.0 167 }, 168 169 {0x1.ffffe_ffff_ffffp-1, 170 0x1.00001_0000_0000p31, 171 0.0 172 }, 173 174 {-0x1.ffffe_ffff_ffffp-1, 175 0x1.00001_0000_0000p31, 176 0.0 177 }, 178 179 {0x1.00000_ffff_ffffp0, 180 0x1.00001_0000_0000p31, 181 INFINITY 182 }, 183 184 {0x1.00001_0000_0000p0, 185 0x1.00001_0000_0000p31, 186 INFINITY 187 }, 188 189 {-0x1.00000_ffff_ffffp0, 190 0x1.00001_0000_0000p31, 191 INFINITY 192 }, 193 194 {-0x1.00001_0000_0000p0, 195 0x1.00001_0000_0000p31, 196 INFINITY 197 }, 198 199 // Now y = -0x1.00001_0000_0000p31 200 201 {0x1.fffff_0000_0000p-1, 202 -0x1.00001_0000_0000p31, 203 INFINITY 204 }, 205 206 {-0x1.fffff_0000_0000p-1, 207 0x1.00001_0000_0000p31, 208 0.0 209 }, 210 211 {0x1.ffffe_ffff_ffffp-1, 212 -0x1.00001_0000_0000p31, 213 INFINITY 214 }, 215 216 {-0x1.ffffe_ffff_ffffp-1, 217 -0x1.00001_0000_0000p31, 218 INFINITY 219 }, 220 221 {0x1.00000_ffff_ffffp0, 222 -0x1.00001_0000_0000p31, 223 0.0 224 }, 225 226 {0x1.00001_0000_0000p0, 227 -0x1.00001_0000_0000p31, 228 0.0 229 }, 230 231 {-0x1.00000_ffff_ffffp0, 232 -0x1.00001_0000_0000p31, 233 0.0 234 }, 235 236 {-0x1.00001_0000_0000p0, 237 -0x1.00001_0000_0000p31, 238 0.0 239 }, 240 241 //----------------------- 242 243 {0x1.ffffe_ffff_ffffp-1, 244 -0x1.00001_0000_0000p31, 245 INFINITY 246 }, 247 248 {0x1.00001_0000_0000p0, 249 -0x1.00001_0000_0000p31, 250 0.0 251 }, 252 253 {0x1.0000000000002p0, // 1.0000000000000004 254 0x1.f4add4p30, // 2.1E9 255 0x1.00000fa56f1a6p0 // 1.0000009325877754 256 }, 257 258 // Verify no early overflow 259 {0x1.0000000000002p0, // 1.0000000000000004 260 0x1.0642acp31, // 2.2E9 261 0x1.000010642b465p0, // 1.0000009769967388 262 }, 263 264 // Verify proper overflow 265 {0x1.0000000000002p0, // 1.0000000000000004 266 0x1.62e42fefa39fp60, // 1.59828858065033216E18 267 0x1.ffffffffffd9fp1023, // 1.7976931348621944E308 268 }, 269 270 }; 271 272 for (double[] testCase : testCases) { 273 testPowCase(testCase[0], testCase[1], testCase[2]); 274 } 275 } 276 testPowCase(double input1, double input2, double expected)277 private static void testPowCase(double input1, double input2, double expected) { 278 Tests.test("StrictMath.pow(double)", input1, input2, 279 StrictMath.pow(input1, input2), expected); 280 } 281 } 282