1 /* 2 * Copyright (c) 2009, 2012, 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 package org.graalvm.compiler.jtt.optimize; 24 25 import org.junit.Test; 26 27 import org.graalvm.compiler.jtt.JTTTest; 28 29 /* 30 */ 31 public class Fold_Math01 extends JTTTest { 32 33 public static double test(int arg) { 34 switch (arg) { 35 case 0: 36 return abs(); 37 case 1: 38 return sin(); 39 case 2: 40 return cos(); 41 case 3: 42 return tan(); 43 case 4: 44 return atan2(); 45 case 5: 46 return sqrt(); 47 case 6: 48 return log(); 49 case 7: 50 return log10(); 51 case 8: 52 return pow(); 53 case 9: 54 return exp(); 55 case 10: 56 return min(); 57 case 11: 58 return max(); 59 } 60 return 42; 61 } 62 63 private static double abs() { 64 return Math.abs(-10.0d); 65 } 66 67 private static double sin() { 68 return Math.sin(0.15d); 69 } 70 71 private static double cos() { 72 return Math.cos(0.15d); 73 } 74 75 private static double tan() { 76 return Math.tan(0.15d); 77 } 78 79 private static double atan2() { 80 return Math.atan2(0.15d, 3.1d); 81 } 82 83 private static double sqrt() { 84 return Math.sqrt(144d); 85 } 86 87 private static double log() { 88 return Math.log(3.15d); 89 } 90 91 private static double log10() { 92 return Math.log10(0.15d); 93 } 94 95 private static double pow() { 96 return Math.pow(2.15d, 6.1d); 97 } 98 99 private static double exp() { 100 return Math.log(3.15d); 101 } 102 103 private static int min() { 104 return Math.min(2, -1); 105 } 106 107 private static int max() { 108 return Math.max(2, -1); 109 } 110 111 @Test 112 public void run0() throws Throwable { 113 runTest("test", 0); 114 } 115 116 @Test 117 public void run1() throws Throwable { 118 runTest("test", 1); 119 } 120 121 @Test 122 public void run2() throws Throwable { 123 runTest("test", 2); 124 } 125 126 @Test 127 public void run3() throws Throwable { 128 runTest("test", 3); 129 } 130 131 @Test 132 public void run4() throws Throwable { 133 runTest("test", 4); 134 } 135 136 @Test 137 public void run5() throws Throwable { 138 runTest("test", 5); 139 } 140 141 @Test 142 public void run6() throws Throwable { 143 runTest("test", 6); 144 } 145 146 @Test 147 public void run7() throws Throwable { 148 runTest("test", 7); 149 } 150 151 @Test 152 public void run8() throws Throwable { 153 runTest("test", 8); 154 } 155 156 @Test 157 public void run9() throws Throwable { 158 runTest("test", 9); 159 } 160 161 @Test 162 public void run10() throws Throwable { 163 runTest("test", 10); 164 } 165 166 @Test 167 public void run11() throws Throwable { 168 runTest("test", 11); 169 } 170 171 @Test 172 public void run12() throws Throwable { 173 runTest("test", 12); 174 } 175 176 }