Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/series/series.java
40948 views
/*1* Copyright (c) 2008, 2020, 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*26* @summary converted from VM Testbase jit/series.27* VM Testbase keywords: [jit, quick]28*29* @library /vmTestbase30* /test/lib31* @run main/othervm jit.series.series32*/3334package jit.series;3536import nsk.share.TestFailure;37import nsk.share.GoldChecker;3839public class series {4041public static final GoldChecker goldChecker = new GoldChecker( "series" );4243private double arithmeticSeries(double i)44{45if (i == 0.0D)46return 0.0D;47else48return i + arithmeticSeries(i - 1.0D);49}5051private float arithmeticSeries(float i)52{53if (i == 0.0F)54return 0.0F;55else56return i + arithmeticSeries(i - 1.0F);57}5859private long arithmeticSeries(long i)60{61if (i == 0L)62return 0L;63else64return i + arithmeticSeries(i - 1L);65}6667private int arithmeticSeries(int i)68{69if (i == 0)70return 0;71else72return i + arithmeticSeries(i - 1);73}7475private double fake(double i)76{77if (i == 0.0D)78return 0.0D;79else80return i + mul100(i - 1.0D);81}82private double mul100(double i)83{84return i * 100.0D;85}8687private float fake(float i)88{89if (i == 0.0F)90return 0.0F;91else92return i + mul100(i - 1.0F);93}94private float mul100(float i)95{96return i * 100F;97}9899private long fake(long i)100{101if (i == 0L)102return 0L;103else104return i + mul100(i - 1L);105}106private long mul100(long i)107{108return i * 100L;109}110111private int fake(int i)112{113if (i == 0)114return 0;115else116return i + mul100(i - 1);117}118private int mul100(int i)119{120return i * 100;121}122123int runit()124{125double dres;126float fres;127long lres;128int res;129int failures = 0;130131res = arithmeticSeries(50);132series.goldChecker.println("1: "+Math.abs(res - 1275));133if (res != 1275) {134series.goldChecker.println(" *** Fail test 1: expected = 1275, computed = " +135res);136failures++;137}138res = fake(50);139series.goldChecker.println("2: "+Math.abs(res - 4950));140if (res != 4950) {141series.goldChecker.println(" *** Fail test 2: expected = 4950, computed = " +142res);143failures++;144}145lres = arithmeticSeries(50L);146series.goldChecker.println("3: "+Math.abs(lres - 1275L));147if (lres != 1275L) {148series.goldChecker.println(" *** Fail test 3: expected = 1275, computed = " +149res);150failures++;151}152lres = fake(50L);153series.goldChecker.println("4: "+Math.abs(lres - 4950L));154if (lres != 4950L) {155series.goldChecker.println(" *** Fail test 4: expected = 4950, computed = " +156res);157failures++;158}159dres = arithmeticSeries(50.0D);160series.goldChecker.println("5: "+Math.abs(dres - 1275.0D));161if (Math.abs(dres - 1275.0D) > 1.0E-09D) {162series.goldChecker.println(" *** Fail test 5: expected = 1275, computed = " +163dres);164failures++;165}166dres = fake(50.0D);167series.goldChecker.println("6: "+Math.abs(dres - 4950.0D));168if (Math.abs(dres - 4950.0D) > 5.0E-09D) {169series.goldChecker.println(" *** Fail test 6: expected = 4950, computed = " +170dres);171failures++;172}173fres = arithmeticSeries(50.0F);174series.goldChecker.println("7: "+Math.abs(fres - 1275.0F));175if (Math.abs(fres - 1275.0F) > 1.0E-04F) {176series.goldChecker.println(" *** Fail test 7: expected = 1275, computed = " +177fres);178failures++;179}180fres = fake(50.0F);181series.goldChecker.println("8: "+Math.abs(fres - 4950.0F));182if (Math.abs(fres - 4950.0F) > 5.0E-04F) {183series.goldChecker.println(" *** Fail test 8: expected = 4950, computed = " +184fres);185failures++;186}187return(failures);188}189190static public void main(String args[])191{192series patObj = new series();193if (patObj.runit()!=0)194throw new TestFailure("Test failed.");;195series.goldChecker.check();196}197}198199200