1 /* 2 * Copyright (c) 2008, 2018, 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 * 27 * @summary converted from VM Testbase jit/FloatingPoint/gen_math/Loops03. 28 * VM Testbase keywords: [jit, quick] 29 * 30 * @library /vmTestbase 31 * /test/lib 32 * @run driver jdk.test.lib.FileInstaller . . 33 * @build jit.FloatingPoint.gen_math.Loops03.Loops03 34 * @run driver ExecDriver --java jit.FloatingPoint.gen_math.Loops03.Loops03 35 */ 36 37 package jit.FloatingPoint.gen_math.Loops03; 38 39 import nsk.share.TestFailure; 40 41 class Loops03 42 { 43 44 static final int N = 100000; 45 46 public static void main (String args[]) 47 { 48 49 50 double x; 51 double r1, r2, r3, r4, r5, r6, r7; 52 double Error = 0.001; 53 54 55 Loops03 ll; 56 ll = new Loops03(); 57 58 int i = 1; 59 double sum = 0; 60 double prod = 1; 61 while(i < N) 62 { r1 = ll.Random_arg(i); 63 r3 = Math.sin(r1); 64 r4 = Math.cos(r1); 65 r5 = r3 * r3 + r4 * r4; 66 r6 = i + i; 67 r7 = r6 * r6; 68 sum = sum + r5/r7; 69 70 r2 = ll.Random_arg(i); 71 r3 = Math.sin(r1); 72 r4 = Math.cos(r1); 73 r5 = r3 * r3 + r4 * r4; 74 r6 = i + i; 75 r7 = r6 * r6; 76 prod = prod * (1 + r5/r7); 77 i++; 78 } 79 double er1 = Math.abs(sum - 0.411); 80 double er2 = Math.abs(prod - 1.465); 81 double errrr = Math.sqrt(er1 * er1 + er2 * er2); 82 83 84 ll.Echeck(errrr,Error); 85 86 } 87 88 // method below return double random number in interval 89 // (0, int nn) 90 91 public double Random_arg(int nn) 92 { 93 double rr; 94 rr = Math.random(); 95 double rn = nn; 96 double ru = rr * rn; 97 return ru; 98 99 } 100 101 public void Echeck(double er, double ER) 102 { 103 104 if( er < ER) 105 System.out.println("test PASS"); 106 else 107 { 108 System.out.println("expected error: " + ER); 109 System.out.println(" found error: " + er); 110 throw new TestFailure("test FAIL"); 111 } 112 113 } 114 115 116 117 118 119 }