Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/math/TestPow0Dot5Opt.java
41153 views
/*1* Copyright (C) 2021 THL A29 Limited, a Tencent company. 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 8265325 826594026* @summary test the optimization of pow(x, 0.5)27* @run main/othervm TestPow0Dot5Opt28* @run main/othervm -Xint TestPow0Dot5Opt29* @run main/othervm -Xbatch -XX:TieredStopAtLevel=1 TestPow0Dot5Opt30* @run main/othervm -Xbatch -XX:-TieredCompilation TestPow0Dot5Opt31*/3233public class TestPow0Dot5Opt {3435static void test(double a) throws Exception {36// pow(x, 0.5) isn't replaced with sqrt(x) for x < 0.037if (a < 0.0) return;3839double r1 = Math.sqrt(a);40double r2 = Math.pow(a, 0.5);41if (r1 != r2) {42throw new RuntimeException("pow(" + a + ", 0.5), expected: " + r1 + ", actual: " + r2);43}4445// Special case: pow(+0.0, 0.5) = 0.046double r = Math.pow(+0.0, 0.5);47if (Double.doubleToRawLongBits(r) != Double.doubleToRawLongBits(0.0)) {48throw new RuntimeException("pow(+0.0, 0.5), expected: 0.0, actual: " + r);49}5051// Special case: pow(-0.0, 0.5) = 0.052r = Math.pow(-0.0, 0.5);53if (Double.doubleToRawLongBits(r) != Double.doubleToRawLongBits(0.0)) {54throw new RuntimeException("pow(-0.0, 0.5), expected: 0.0, actual: " + r);55}5657// Special case: pow(Double.POSITIVE_INFINITY, 0.5) = Infinity58r = Math.pow(Double.POSITIVE_INFINITY, 0.5);59if (!(r > 0 && Double.isInfinite(r))) {60throw new RuntimeException("pow(+Infinity, 0.5), expected: Infinity, actual: " + r);61}6263// Special case: pow(Double.NEGATIVE_INFINITY, 0.5) = Infinity64r = Math.pow(Double.NEGATIVE_INFINITY, 0.5);65if (!(r > 0 && Double.isInfinite(r))) {66throw new RuntimeException("pow(-Infinity, 0.5), expected: Infinity, actual: " + r);67}6869// Special case: pow(Double.NaN, 0.5) = NaN70r = Math.pow(Double.NaN, 0.5);71if (!Double.isNaN(r)) {72throw new RuntimeException("pow(NaN, 0.5), expected: NaN, actual: " + r);73}74}7576public static void main(String[] args) throws Exception {77for (int i = 0; i < 10; i++) {78for (int j = 1; j < 100000; j++) {79test(j * 1.0);80test(1.0 / j);81}82}83}8485}868788