1 /* 2 * Copyright (c) 2008, 2020, 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/Filtering. 28 * VM Testbase keywords: [jit, quick] 29 * 30 * @library /vmTestbase 31 * /test/lib 32 * @run main/othervm jit.FloatingPoint.gen_math.Filtering.Filtering 33 */ 34 35 package jit.FloatingPoint.gen_math.Filtering; 36 37 import nsk.share.TestFailure; 38 39 public class Filtering 40 { 41 static int N = 1000; 42 static double xx[]; 43 static double yy[]; 44 main(String args[])45 public static void main (String args[]) 46 { 47 48 double Error = 0.0001; 49 50 xx = new double[N]; 51 yy = new double[N]; 52 53 54 double r1, r2, r3, r4; 55 56 double rn = N; 57 double dx = 1/rn; 58 double A = 0.5; 59 double B = 0.75; 60 61 for(int i = 0; i < N; i++) 62 { r1 = i * dx; 63 xx[i] = A * Math.sin(3 * r1) + B * Math.cos(3 * r1); 64 } 65 66 Filtering ff; 67 ff = new Filtering(); 68 69 double normaX = ff.Norma1(N,xx); 70 71 ff.Filter1(N); 72 double norma1 = ff.Norma1(N,yy); 73 74 ff.Filter2(N); 75 double norma2 = ff.Norma1(N,yy); 76 77 ff.Filter3(N); 78 double norma3 = ff.Norma1(N,yy); 79 80 r4 = (norma1 * norma1 + norma2 * norma2 + norma3 * norma3) / 3 ; 81 r4 = Math.sqrt(r4); 82 double errrr = Math.abs(r4 - normaX); 83 84 ff.Echeck(errrr,Error); 85 86 } 87 Norma1(int nn, double uu[])88 public double Norma1(int nn, double uu[]) 89 { 90 double nor = 0; 91 double r1 = nn; 92 double r2; 93 for(int i = 0; i < nn; i++) 94 { r2 = uu[i] * uu[i]; 95 nor = nor + r2; 96 } 97 nor = nor / r1; 98 return nor; 99 } 100 101 Filter1(int nn)102 public void Filter1 (int nn) 103 { yy[0] = xx[0]; 104 yy[nn - 1] = xx[nn - 1]; 105 for(int i = 1; i < nn - 1; i++) 106 { 107 yy[i] = 0.5 * (xx[i - 1] + xx[i + 1]); 108 } 109 } 110 111 Filter2(int nn)112 public void Filter2 (int nn) 113 { yy[0] = xx[0]; 114 yy[nn - 1] = xx[nn - 1]; 115 for(int i = 1; i < nn - 1; i++) 116 { 117 yy[i] = 0.25 * (xx[i - 1] + 2 * xx[i] + xx[i + 1]); 118 } 119 120 } 121 Filter3(int nn)122 public void Filter3 (int nn) 123 { yy[0] = xx[0]; 124 yy[nn - 1] = xx[nn - 1]; 125 yy[1] = 0.5 * (xx[0] + xx[2]); 126 yy[nn - 2] = 0.5 * (xx[nn - 1] + xx[nn - 3]); 127 for(int i = 2; i < nn - 2; i++) 128 { 129 yy[i] = 0.1 * (xx[i - 2] + 2 * xx[i - 1] + 4 * xx[i] + 130 2 * xx[i + 1] + xx[i + 2]); 131 } 132 133 } 134 135 136 137 138 Echeck(double er, double ER)139 public void Echeck(double er, double ER) 140 { 141 142 if( er < ER) 143 System.out.println("test PASS"); 144 else 145 { 146 System.out.println("expected error: " + ER); 147 System.out.println(" found error: " + er); 148 throw new TestFailure("test FAIL"); 149 150 } 151 152 } 153 154 155 156 157 158 159 } 160