blob: afc5e976d98e1a694b1710234085eab6c2b9aaab [file] [log] [blame]
Elliott Hughes4c6aad22013-04-01 15:47:17 -07001/*
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
17public 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 Katkove90501d2014-03-12 15:56:54 +070022 test1();
23 test2();
24 }
25
26 public static void test1() {
Elliott Hughes4c6aad22013-04-01 15:47:17 -070027
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 Katkove90501d2014-03-12 15:56:54 +070043 System.out.println("Iteration Result is as expected");
Elliott Hughes4c6aad22013-04-01 15:47:17 -070044 } else {
45 System.out.println("Conversions failed over " + NUM_ITERATIONS + " iterations");
46 }
47 }
Serguei Katkove90501d2014-03-12 15:56:54 +070048
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 Hughes4c6aad22013-04-01 15:47:17 -070058}