MinMax.java revision 2362
809N/A/*
2362N/A * Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.
809N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
809N/A *
809N/A * This code is free software; you can redistribute it and/or modify it
809N/A * under the terms of the GNU General Public License version 2 only, as
809N/A * published by the Free Software Foundation.
809N/A *
809N/A * This code is distributed in the hope that it will be useful, but WITHOUT
809N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
809N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
809N/A * version 2 for more details (a copy is included in the LICENSE file that
809N/A * accompanied this code).
809N/A *
809N/A * You should have received a copy of the GNU General Public License version
809N/A * 2 along with this work; if not, write to the Free Software Foundation,
809N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
809N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
809N/A */
809N/A
809N/A/* @test
809N/A @bug 4010528 4010529
809N/A @summary Math.min and Math.max should treat negative zero as strictly
809N/A less than positive zero
809N/A */
809N/A
809N/A
809N/Apublic class MinMax {
809N/A
809N/A
809N/A static void go(String what, float result, float correctResult) {
809N/A String v = what + ": got " + result + ", expected " + correctResult;
809N/A if (!(Float.toString(result).equals(Float.toString(correctResult))))
809N/A throw new RuntimeException(v);
809N/A System.err.println(v);
809N/A }
809N/A
809N/A static void go(String what, double result, double correctResult) {
809N/A String v = what + ": got " + result + ", expected " + correctResult;
809N/A if (!(Double.toString(result).equals(Double.toString(correctResult))))
809N/A throw new RuntimeException(v);
809N/A System.err.println(v);
809N/A }
809N/A
809N/A
809N/A public static void main(String[] args) {
809N/A
809N/A float fnz = -0.0f;
809N/A float fpz = +0.0f;
809N/A
809N/A go("Math.min(fnz, fnz)", Math.min(fnz, fnz), fnz);
809N/A go("Math.min(fnz, fpz)", Math.min(fnz, fpz), fnz);
809N/A go("Math.min(fpz, fnz)", Math.min(fpz, fnz), fnz);
809N/A go("Math.min(fpz, fpz)", Math.min(fpz, fpz), fpz);
809N/A
809N/A go("Math.min(-1.0f, fnz)", Math.min(-1.0f, fnz), -1.0f);
809N/A go("Math.min(-1.0f, fpz)", Math.min(-1.0f, fpz), -1.0f);
809N/A go("Math.min(+1.0f, fnz)", Math.min(+1.0f, fnz), fnz);
809N/A go("Math.min(+1.0f, fpz)", Math.min(+1.0f, fpz), fpz);
809N/A go("Math.min(-1.0f, +1.0f)", Math.min(-1.0f, +1.0f), -1.0f);
809N/A go("Math.min(fnz, -1.0f)", Math.min(fnz, -1.0f), -1.0f);
809N/A go("Math.min(fpz, -1.0f)", Math.min(fpz, -1.0f), -1.0f);
809N/A go("Math.min(fnz, +1.0f)", Math.min(fnz, +1.0f), fnz);
809N/A go("Math.min(fpz, +1.0f)", Math.min(fpz, +1.0f), fpz);
809N/A go("Math.min(+1.0f, -1.0f)", Math.min(+1.0f, -1.0f), -1.0f);
809N/A
809N/A go("Math.max(fnz, fnz)", Math.max(fnz, fnz), fnz);
809N/A go("Math.max(fnz, fpz)", Math.max(fnz, fpz), fpz);
809N/A go("Math.max(fpz, fnz)", Math.max(fpz, fnz), fpz);
809N/A go("Math.max(fpz, fpz)", Math.max(fpz, fpz), fpz);
809N/A
809N/A go("Math.max(-1.0f, fnz)", Math.max(-1.0f, fnz), fnz);
809N/A go("Math.max(-1.0f, fpz)", Math.max(-1.0f, fpz), fpz);
809N/A go("Math.max(+1.0f, fnz)", Math.max(+1.0f, fnz), +1.0f);
809N/A go("Math.max(+1.0f, fpz)", Math.max(+1.0f, fpz), +1.0f);
809N/A go("Math.max(-1.0f, +1.0f)", Math.max(-1.0f, +1.0f), +1.0f);
809N/A go("Math.max(fnz, -1.0f)", Math.max(fnz, -1.0f), fnz);
809N/A go("Math.max(fpz, -1.0f)", Math.max(fpz, -1.0f), fpz);
809N/A go("Math.max(fnz, +1.0f)", Math.max(fnz, +1.0f), +1.0f);
809N/A go("Math.max(fpz, +1.0f)", Math.max(fpz, +1.0f), +1.0f);
809N/A go("Math.max(+1.0f, -1.0f)", Math.max(+1.0f, -1.0f), +1.0f);
809N/A
809N/A
809N/A double dnz = -0.0d;
809N/A double dpz = +0.0d;
809N/A
809N/A go("Math.min(dnz, dnz)", Math.min(dnz, dnz), dnz);
809N/A go("Math.min(dnz, dpz)", Math.min(dnz, dpz), dnz);
809N/A go("Math.min(dpz, dnz)", Math.min(dpz, dnz), dnz);
809N/A go("Math.min(dpz, dpz)", Math.min(dpz, dpz), dpz);
809N/A
809N/A go("Math.min(-1.0d, dnz)", Math.min(-1.0d, dnz), -1.0d);
809N/A go("Math.min(-1.0d, dpz)", Math.min(-1.0d, dpz), -1.0d);
809N/A go("Math.min(+1.0d, dnz)", Math.min(+1.0d, dnz), dnz);
809N/A go("Math.min(+1.0d, dpz)", Math.min(+1.0d, dpz), dpz);
809N/A go("Math.min(-1.0d, +1.0d)", Math.min(-1.0d, +1.0d), -1.0d);
809N/A go("Math.min(dnz, -1.0d)", Math.min(dnz, -1.0d), -1.0d);
809N/A go("Math.min(dpz, -1.0d)", Math.min(dpz, -1.0d), -1.0d);
809N/A go("Math.min(dnz, +1.0d)", Math.min(dnz, +1.0d), dnz);
809N/A go("Math.min(dpz, +1.0d)", Math.min(dpz, +1.0d), dpz);
809N/A go("Math.min(+1.0d, -1.0d)", Math.min(+1.0d, -1.0d), -1.0d);
809N/A
809N/A go("Math.max(dnz, dnz)", Math.max(dnz, dnz), dnz);
809N/A go("Math.max(dnz, dpz)", Math.max(dnz, dpz), dpz);
809N/A go("Math.max(dpz, dnz)", Math.max(dpz, dnz), dpz);
809N/A go("Math.max(dpz, dpz)", Math.max(dpz, dpz), dpz);
809N/A
809N/A go("Math.max(-1.0d, dnz)", Math.max(-1.0d, dnz), dnz);
809N/A go("Math.max(-1.0d, dpz)", Math.max(-1.0d, dpz), dpz);
809N/A go("Math.max(+1.0d, dnz)", Math.max(+1.0d, dnz), +1.0d);
809N/A go("Math.max(+1.0d, dpz)", Math.max(+1.0d, dpz), +1.0d);
809N/A go("Math.max(-1.0d, +1.0d)", Math.max(-1.0d, +1.0d), +1.0d);
809N/A go("Math.max(dnz, -1.0d)", Math.max(dnz, -1.0d), dnz);
809N/A go("Math.max(dpz, -1.0d)", Math.max(dpz, -1.0d), dpz);
809N/A go("Math.max(dnz, +1.0d)", Math.max(dnz, +1.0d), +1.0d);
809N/A go("Math.max(dpz, +1.0d)", Math.max(dpz, +1.0d), +1.0d);
809N/A go("Math.max(+1.0d, -1.0d)", Math.max(+1.0d, -1.0d), +1.0d);
809N/A
809N/A }
809N/A
809N/A}