| 1 |
/* |
| 2 |
* Copyright (C) 2015 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 |
public static void floatTest() { |
| 19 |
float f = 0; |
| 20 |
float nf = -0; |
| 21 |
float fc = 1f; |
| 22 |
for (int i = 0; i < 2; i++) { |
| 23 |
f -= fc; |
| 24 |
f = -f; |
| 25 |
nf -= fc; |
| 26 |
nf = -nf; |
| 27 |
} |
| 28 |
|
| 29 |
System.out.println(f); |
| 30 |
System.out.println(nf); |
| 31 |
System.out.println(f + 0f); |
| 32 |
System.out.println(f - (-0f)); |
| 33 |
System.out.println(-f - (-nf)); |
| 34 |
System.out.println(-f + (-nf)); |
| 35 |
} |
| 36 |
|
| 37 |
public static void doubleTest() { |
| 38 |
double d = 0; |
| 39 |
double nd = -0; |
| 40 |
double dc = 1f; |
| 41 |
for (int i = 0; i < 2; i++) { |
| 42 |
d -= dc; |
| 43 |
d = -d; |
| 44 |
nd -= dc; |
| 45 |
nd = -nd; |
| 46 |
} |
| 47 |
|
| 48 |
System.out.println(d); |
| 49 |
System.out.println(nd); |
| 50 |
System.out.println(d + 0f); |
| 51 |
System.out.println(d - (-0f)); |
| 52 |
System.out.println(-d - (-nd)); |
| 53 |
System.out.println(-d + (-nd)); |
| 54 |
} |
| 55 |
|
| 56 |
public static void bug_1() { |
| 57 |
int i4=18, i3=-48959; |
| 58 |
float d; |
| 59 |
float f=-0.0f; |
| 60 |
float a=0.0f; |
| 61 |
|
| 62 |
d = -f + (-a); |
| 63 |
f += i4 * i3; |
| 64 |
|
| 65 |
System.out.println("d " + d); |
| 66 |
} |
| 67 |
|
| 68 |
public static void main(String[] args) { |
| 69 |
doubleTest(); |
| 70 |
floatTest(); |
| 71 |
bug_1(); |
| 72 |
} |
| 73 |
|
| 74 |
} |