Path: blob/master/test/jdk/java/lang/Math/MinMax.java
41152 views
/*1* Copyright (c) 1997, 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 4010528 401052925@summary Math.min and Math.max should treat negative zero as strictly26less than positive zero27*/282930public class MinMax {313233static void go(String what, float result, float correctResult) {34String v = what + ": got " + result + ", expected " + correctResult;35if (!(Float.toString(result).equals(Float.toString(correctResult))))36throw new RuntimeException(v);37System.err.println(v);38}3940static void go(String what, double result, double correctResult) {41String v = what + ": got " + result + ", expected " + correctResult;42if (!(Double.toString(result).equals(Double.toString(correctResult))))43throw new RuntimeException(v);44System.err.println(v);45}464748public static void main(String[] args) {4950float fnz = -0.0f;51float fpz = +0.0f;5253go("Math.min(fnz, fnz)", Math.min(fnz, fnz), fnz);54go("Math.min(fnz, fpz)", Math.min(fnz, fpz), fnz);55go("Math.min(fpz, fnz)", Math.min(fpz, fnz), fnz);56go("Math.min(fpz, fpz)", Math.min(fpz, fpz), fpz);5758go("Math.min(-1.0f, fnz)", Math.min(-1.0f, fnz), -1.0f);59go("Math.min(-1.0f, fpz)", Math.min(-1.0f, fpz), -1.0f);60go("Math.min(+1.0f, fnz)", Math.min(+1.0f, fnz), fnz);61go("Math.min(+1.0f, fpz)", Math.min(+1.0f, fpz), fpz);62go("Math.min(-1.0f, +1.0f)", Math.min(-1.0f, +1.0f), -1.0f);63go("Math.min(fnz, -1.0f)", Math.min(fnz, -1.0f), -1.0f);64go("Math.min(fpz, -1.0f)", Math.min(fpz, -1.0f), -1.0f);65go("Math.min(fnz, +1.0f)", Math.min(fnz, +1.0f), fnz);66go("Math.min(fpz, +1.0f)", Math.min(fpz, +1.0f), fpz);67go("Math.min(+1.0f, -1.0f)", Math.min(+1.0f, -1.0f), -1.0f);6869go("Math.max(fnz, fnz)", Math.max(fnz, fnz), fnz);70go("Math.max(fnz, fpz)", Math.max(fnz, fpz), fpz);71go("Math.max(fpz, fnz)", Math.max(fpz, fnz), fpz);72go("Math.max(fpz, fpz)", Math.max(fpz, fpz), fpz);7374go("Math.max(-1.0f, fnz)", Math.max(-1.0f, fnz), fnz);75go("Math.max(-1.0f, fpz)", Math.max(-1.0f, fpz), fpz);76go("Math.max(+1.0f, fnz)", Math.max(+1.0f, fnz), +1.0f);77go("Math.max(+1.0f, fpz)", Math.max(+1.0f, fpz), +1.0f);78go("Math.max(-1.0f, +1.0f)", Math.max(-1.0f, +1.0f), +1.0f);79go("Math.max(fnz, -1.0f)", Math.max(fnz, -1.0f), fnz);80go("Math.max(fpz, -1.0f)", Math.max(fpz, -1.0f), fpz);81go("Math.max(fnz, +1.0f)", Math.max(fnz, +1.0f), +1.0f);82go("Math.max(fpz, +1.0f)", Math.max(fpz, +1.0f), +1.0f);83go("Math.max(+1.0f, -1.0f)", Math.max(+1.0f, -1.0f), +1.0f);848586double dnz = -0.0d;87double dpz = +0.0d;8889go("Math.min(dnz, dnz)", Math.min(dnz, dnz), dnz);90go("Math.min(dnz, dpz)", Math.min(dnz, dpz), dnz);91go("Math.min(dpz, dnz)", Math.min(dpz, dnz), dnz);92go("Math.min(dpz, dpz)", Math.min(dpz, dpz), dpz);9394go("Math.min(-1.0d, dnz)", Math.min(-1.0d, dnz), -1.0d);95go("Math.min(-1.0d, dpz)", Math.min(-1.0d, dpz), -1.0d);96go("Math.min(+1.0d, dnz)", Math.min(+1.0d, dnz), dnz);97go("Math.min(+1.0d, dpz)", Math.min(+1.0d, dpz), dpz);98go("Math.min(-1.0d, +1.0d)", Math.min(-1.0d, +1.0d), -1.0d);99go("Math.min(dnz, -1.0d)", Math.min(dnz, -1.0d), -1.0d);100go("Math.min(dpz, -1.0d)", Math.min(dpz, -1.0d), -1.0d);101go("Math.min(dnz, +1.0d)", Math.min(dnz, +1.0d), dnz);102go("Math.min(dpz, +1.0d)", Math.min(dpz, +1.0d), dpz);103go("Math.min(+1.0d, -1.0d)", Math.min(+1.0d, -1.0d), -1.0d);104105go("Math.max(dnz, dnz)", Math.max(dnz, dnz), dnz);106go("Math.max(dnz, dpz)", Math.max(dnz, dpz), dpz);107go("Math.max(dpz, dnz)", Math.max(dpz, dnz), dpz);108go("Math.max(dpz, dpz)", Math.max(dpz, dpz), dpz);109110go("Math.max(-1.0d, dnz)", Math.max(-1.0d, dnz), dnz);111go("Math.max(-1.0d, dpz)", Math.max(-1.0d, dpz), dpz);112go("Math.max(+1.0d, dnz)", Math.max(+1.0d, dnz), +1.0d);113go("Math.max(+1.0d, dpz)", Math.max(+1.0d, dpz), +1.0d);114go("Math.max(-1.0d, +1.0d)", Math.max(-1.0d, +1.0d), +1.0d);115go("Math.max(dnz, -1.0d)", Math.max(dnz, -1.0d), dnz);116go("Math.max(dpz, -1.0d)", Math.max(dpz, -1.0d), dpz);117go("Math.max(dnz, +1.0d)", Math.max(dnz, +1.0d), +1.0d);118go("Math.max(dpz, +1.0d)", Math.max(dpz, +1.0d), +1.0d);119go("Math.max(+1.0d, -1.0d)", Math.max(+1.0d, -1.0d), +1.0d);120121}122123}124125126