Path: blob/master/test/jdk/java/lang/Float/Constants.java
41149 views
/*1* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @compile Constants.java26* @bug 4397405 482665227* @summary Testing constant-ness of Float.{MIN_VALUE, MAX_VALUE}, etc.28* @author Joseph D. Darcy29*/3031public class Constants {32/*33* This compile-only test is to make sure that the primitive34* public static final fields in java.lang.Float are "constant35* expressions" as defined by "The Java Language Specification,36* 2nd edition" section 15.28; a different test checks the values37* of those fields.38*/39public static void main(String[] args) throws Exception {40int i = 0;41switch (i) {42case (int)Float.NaN: // 043System.out.println("Float.NaN is a constant!");44break;45case (int)Float.MIN_VALUE + 1: // 0 + 146System.out.println("Float.MIN_VALUE is a constant!");47break;48case (int)Float.MIN_NORMAL + 2: // 0 + 249System.out.println("Float.MIN_NORMAL is a constant!");50break;51case Float.MIN_EXPONENT: // -12652System.out.println("Float.MIN_EXPONENT is a constant!");53break;54case Float.MAX_EXPONENT: // 12755System.out.println("Float.MAX_EXPONENT is a constant!");56break;57case (int)Float.MAX_VALUE - 1: // Integer.MAX_VALUE - 158System.out.println("Float.MAX_VALUE is a constant!");59break;60case (int)Float.POSITIVE_INFINITY: // Integer.MAX_VALUE61System.out.println("Float.POSITIVE_INFINITY is a constant!");62break;63case (int)Float.NEGATIVE_INFINITY: // Integer.MIN_VALUE64System.out.println("Float.NEGATIVE_INFINITY is a constant!");65break;66}67}68}697071