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 fc = 1f; 21 for (int i = 0; i < 2; i++) { 22 f -= fc; 23 f = -f; 24 } 25 26 System.out.println(f); 27 System.out.println(f + 0f); 28 System.out.println(f - (-0f)); 29 } 30 31 public static void doubleTest() { 32 double d = 0; 33 double dc = 1f; 34 for (int i = 0; i < 2; i++) { 35 d -= dc; 36 d = -d; 37 } 38 39 System.out.println(d); 40 System.out.println(d + 0f); 41 System.out.println(d - (-0f)); 42 } 43 44 public static void main(String[] args) { 45 doubleTest(); 46 floatTest(); 47 } 48 49 } 50