| anuvarsh | 04968fa | 2019-06-11 14:38:51 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | class Main { |
| 18 | final static int iterations = 10; |
| 19 | |
| 20 | public static void assertIntEquals(int expected, int result) { |
| 21 | if (expected != result) { |
| 22 | throw new Error("Expected: " + expected + ", found: " + result); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | public static void assertDoubleEquals(double expected, double result) { |
| 27 | if (expected != result) { |
| 28 | throw new Error("Expected: " + expected + ", found: " + result); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public static void assertFloatEquals(float expected, float result) { |
| 33 | if (expected != result) { |
| 34 | throw new Error("Expected: " + expected + ", found: " + result); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public static void assertLongEquals(long expected, long result) { |
| 39 | if (expected != result) { |
| 40 | throw new Error("Expected: " + expected + ", found: " + result); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | |
| 45 | public static long simpleMethod(long jj, long kk) { |
| 46 | jj = jj >>> kk; |
| 47 | return jj; |
| 48 | } |
| 49 | public static int simpleMethod1(int jj, int kk) { |
| 50 | jj = jj << kk; |
| 51 | jj = jj << kk; |
| 52 | return jj; |
| 53 | } |
| 54 | public static float simpleMethod2(float jj, float ii) { |
| 55 | jj = ii / jj; |
| 56 | jj = jj / ii; |
| 57 | return jj; |
| 58 | } |
| 59 | |
| 60 | public static void main(String[] args) { |
| 61 | long workJ = 0xFFEFAAAA; |
| 62 | long workK = 0xF8E9BBBB; |
| 63 | int workJ1 = 0xFFEF; |
| 64 | int workK1 = 0xF8E9; |
| 65 | float workJ2 = 10.0f; |
| 66 | float workK2 = 15.0f; |
| 67 | |
| 68 | |
| 69 | |
| 70 | for (long i = 0; i < iterations; i++) { |
| 71 | workJ = simpleMethod(workJ, workK) + i; |
| 72 | } |
| 73 | assertLongEquals(workJ, 9); |
| 74 | |
| 75 | for (int i = 0; i < iterations; i++) { |
| 76 | workJ1 = simpleMethod1(workJ1, workK1) + i; |
| 77 | } |
| 78 | assertIntEquals(workJ1, 2097161); |
| 79 | |
| 80 | for (float i = 0.0f; i < iterations; i++) { |
| 81 | workJ2 = simpleMethod2(workJ2, workK2) + i; |
| 82 | } |
| 83 | assertFloatEquals(workJ2, 9.122855f); |
| 84 | } |
| 85 | } |