Path: blob/master/test/jdk/java/lang/Math/AbsPositiveZero.java
41152 views
/*1* Copyright (c) 1998, 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/* @test24@bug 409627825@summary Math.abs(+0.0) wrong26@author Anand Palaniswamy27*/28public class AbsPositiveZero {29private static boolean isPositiveZero(float f) {30return Float.floatToIntBits(f) == Float.floatToIntBits(0.0f);31}3233private static boolean isPositiveZero(double d) {34return Double.doubleToLongBits(d) == Double.doubleToLongBits(0.0d);35}3637public static void main(String[] args) throws Exception {38if (!isPositiveZero(Math.abs(-0.0d))) {39throw new Exception("abs(-0.0d) failed");40}41if (!isPositiveZero(Math.abs(+0.0d))) {42throw new Exception("abs(+0.0d) failed");43}44if (Math.abs(Double.POSITIVE_INFINITY) != Double.POSITIVE_INFINITY) {45throw new Exception("abs(+Inf) failed");46}47if (Math.abs(Double.NEGATIVE_INFINITY) != Double.POSITIVE_INFINITY) {48throw new Exception("abs(-Inf) failed");49}50double dnanval = Math.abs(Double.NaN);51if (dnanval == dnanval) {52throw new Exception("abs(NaN) failed");53}5455if (!isPositiveZero(Math.abs(-0.0f))) {56throw new Exception("abs(-0.0f) failed");57}58if (!isPositiveZero(Math.abs(+0.0f))) {59throw new Exception("abs(+0.0f) failed");60}61if (Math.abs(Float.POSITIVE_INFINITY) != Float.POSITIVE_INFINITY) {62throw new Exception("abs(+Inf) failed");63}64if (Math.abs(Float.NEGATIVE_INFINITY) != Float.POSITIVE_INFINITY) {65throw new Exception("abs(-Inf) failed");66}67float fnanval = Math.abs(Float.NaN);68if (fnanval == fnanval) {69throw new Exception("abs(NaN) failed");70}71}72}737475