Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/misctests/Pi/Pi.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* @key randomness26*27* @summary converted from VM Testbase jit/misctests/Pi.28* VM Testbase keywords: [jit, quick]29*30* @library /vmTestbase31* /test/lib32* @run main/othervm jit.misctests.Pi.Pi33*/3435package jit.misctests.Pi;3637import java.util.Random;38import nsk.share.TestFailure;39import jdk.test.lib.Utils;4041public class Pi{42static double pi;43static int imKreis=0, imQuadrat=0, i=0;4445public static void main(String args[]) {46for(int i=0;i<=100;i++) {47wurf(10000);48pi=4.0*imKreis/imQuadrat;49ausgabe();50}51System.out.print("\n");52}5354static void wurf(int wieOft) {55double x,y;56Random zufall;57zufall = Utils.getRandomInstance();58for(int i=0;i<=wieOft;i++) {59x=zufall.nextDouble();60y=zufall.nextDouble();61imQuadrat++;62if(x*x+y*y<1)imKreis++;63}64}6566static void ausgabe() {67System.out.print(pi);68if ((++i % 4) == 0){69System.out.print("\n");70} else {71System.out.print(" ");72}73}74}757677