Elliott Hughes | 4c6aad2 | 2013-04-01 15:47:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | public class Main { |
| 18 | static final long NUM_ITERATIONS = 50000; |
| 19 | static volatile double negInfinity = Double.NEGATIVE_INFINITY; |
| 20 | |
| 21 | public static void main(String args[]) { |
Serguei Katkov | e90501d | 2014-03-12 15:56:54 +0700 | [diff] [blame] | 22 | test1(); |
| 23 | test2(); |
| 24 | } |
| 25 | |
| 26 | public static void test1() { |
Elliott Hughes | 4c6aad2 | 2013-04-01 15:47:17 -0700 | [diff] [blame] | 27 | |
| 28 | long sumInf = 0; |
| 29 | long sumRes = 0; |
| 30 | |
| 31 | for (long i = 0 ; i < NUM_ITERATIONS ; i++) { |
| 32 | //Every second iteration, sumInf becomes 0 |
| 33 | sumInf += (long) negInfinity; |
| 34 | |
| 35 | //Some extra work for compilers to make this |
| 36 | //loop seem important |
| 37 | if (sumInf == Long.MIN_VALUE) { |
| 38 | sumRes++; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if (sumRes == NUM_ITERATIONS / 2) { |
Serguei Katkov | e90501d | 2014-03-12 15:56:54 +0700 | [diff] [blame] | 43 | System.out.println("Iteration Result is as expected"); |
Elliott Hughes | 4c6aad2 | 2013-04-01 15:47:17 -0700 | [diff] [blame] | 44 | } else { |
| 45 | System.out.println("Conversions failed over " + NUM_ITERATIONS + " iterations"); |
| 46 | } |
| 47 | } |
Serguei Katkov | e90501d | 2014-03-12 15:56:54 +0700 | [diff] [blame] | 48 | |
| 49 | public static void test2() { |
| 50 | long a = 1L; |
| 51 | long b = 2L; |
| 52 | |
| 53 | float inter3 = a; |
| 54 | float inter4 = b; |
| 55 | System.out.println("inter4:" + inter4); |
| 56 | } |
| 57 | |
Elliott Hughes | 4c6aad2 | 2013-04-01 15:47:17 -0700 | [diff] [blame] | 58 | } |