hotspot/test/compiler/c2/FloatingPointFoldingTest.java
author stsmirno
Mon, 17 Oct 2016 18:54:12 -0400
changeset 41705 332239c052cc
parent 40059 c2304140ed64
permissions -rw-r--r--
8165687: Fix license and copyright headers in jd9 under hotspot/test Summary: Legal notices and Oracle copyrights were updated (white and blank space, commas) in tests files for uniformity to meet Oracle requirements. Reviewed-by: dholmes, iris Contributed-by: Stanislav Smirnov <stanislav.smirnov@oracle.com>, Vassili Igouchkine <vassili.igouchkine@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29346
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     1
/*
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     4
 *
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     8
 *
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    13
 * accompanied this code).
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    14
 *
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    18
 *
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    21
 * questions.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    22
 */
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    23
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    24
/**
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    25
 * @test
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    26
 * @bug 8073670
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    27
 * @summary Test that causes C2 to fold two NaNs with different values into a single NaN.
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    28
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    29
 * @run main/othervm -XX:-TieredCompilation -Xcomp
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    30
 *      -XX:CompileCommand=compileonly,compiler.c2.FloatingPointFoldingTest::test_double_inf
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    31
 *      -XX:CompileCommand=compileonly,compiler.c2.FloatingPointFoldingTest::test_double_zero
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    32
 *      -XX:CompileCommand=compileonly,compiler.c2.FloatingPointFoldingTest::test_double_nan
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    33
 *      -XX:CompileCommand=compileonly,compiler.c2.FloatingPointFoldingTest::test_float_inf
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    34
 *      -XX:CompileCommand=compileonly,compiler.c2.FloatingPointFoldingTest::test_float_zero
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    35
 *      -XX:CompileCommand=compileonly,compiler.c2.FloatingPointFoldingTest::test_float_nan
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    36
 *      compiler.c2.FloatingPointFoldingTest
29346
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    37
 */
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    38
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    39
package compiler.c2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 29346
diff changeset
    40
29346
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    41
public class FloatingPointFoldingTest {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    42
    // Double values.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    43
    public static final long MINUS_INF_LONGBITS = 0xfff0000000000000L;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    44
    public static final double DOUBLE_MINUS_INF = Double.longBitsToDouble(MINUS_INF_LONGBITS);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    45
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    46
    public static final long PLUS_INF_LONGBITS = 0x7ff0000000000000L;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    47
    public static final double DOUBLE_PLUS_INF = Double.longBitsToDouble(PLUS_INF_LONGBITS);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    48
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    49
    public static final long MINUS_ZERO_LONGBITS = 0x8000000000000000L;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    50
    public static final double DOUBLE_MINUS_ZERO = Double.longBitsToDouble(MINUS_ZERO_LONGBITS);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    51
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    52
    // We need two different NaN values. A floating point number is
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    53
    // considered to be NaN is the sign bit is 0, all exponent bits
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    54
    // are set to 1, and at least one bit of the exponent is not zero.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    55
    //
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    56
    // As java.lang.Double.NaN is 0x7ff8000000000000L, we use
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    57
    // 0x7ffc000000000000L as a second NaN double value.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    58
    public static final long NAN_LONGBITS = 0x7ffc000000000000L;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    59
    public static final double DOUBLE_NAN = Double.longBitsToDouble(NAN_LONGBITS);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    60
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    61
    // Float values.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    62
    public static final int MINUS_INF_INTBITS = 0xff800000;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    63
    public static final float FLOAT_MINUS_INF = Float.intBitsToFloat(MINUS_INF_INTBITS);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    64
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    65
    public static final int PLUS_INF_INTBITS = 0x7f800000;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    66
    public static final float FLOAT_PLUS_INF = Float.intBitsToFloat(PLUS_INF_INTBITS);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    67
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    68
    public static final int MINUS_ZERO_INTBITS = 0x80000000;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    69
    public static final float FLOAT_MINUS_ZERO = Float.intBitsToFloat(MINUS_ZERO_INTBITS);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    70
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    71
    // As java.lang.Float.NaN is 0x7fc00000, we use 0x7fe00000
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    72
    // as a second NaN float value.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    73
    public static final int NAN_INTBITS = 0x7fe00000;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    74
    public static final float FLOAT_NAN = Float.intBitsToFloat(NAN_INTBITS);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    75
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    76
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    77
    // Double tests.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    78
    static void test_double_inf(long[] result) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    79
        double d1 = DOUBLE_MINUS_INF;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    80
        double d2 = DOUBLE_PLUS_INF;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    81
        result[0] = Double.doubleToRawLongBits(d1);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    82
        result[1] = Double.doubleToRawLongBits(d2);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    83
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    84
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    85
    static void test_double_zero(long[] result) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    86
        double d1 = DOUBLE_MINUS_ZERO;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    87
        double d2 = 0;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    88
        result[0] = Double.doubleToRawLongBits(d1);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    89
        result[1] = Double.doubleToRawLongBits(d2);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    90
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    91
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    92
    static void test_double_nan(long[] result) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    93
        double d1 = DOUBLE_NAN;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    94
        double d2 = Double.NaN;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    95
        result[0] = Double.doubleToRawLongBits(d1);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    96
        result[1] = Double.doubleToRawLongBits(d2);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    97
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    98
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
    99
    // Float tests.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   100
    static void test_float_inf(int[] result) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   101
        float f1 = FLOAT_MINUS_INF;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   102
        float f2 = FLOAT_PLUS_INF;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   103
        result[0] = Float.floatToRawIntBits(f1);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   104
        result[1] = Float.floatToRawIntBits(f2);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   105
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   106
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   107
    static void test_float_zero(int[] result) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   108
        float f1 = FLOAT_MINUS_ZERO;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   109
        float f2 = 0;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   110
        result[0] = Float.floatToRawIntBits(f1);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   111
        result[1] = Float.floatToRawIntBits(f2);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   112
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   113
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   114
    static void test_float_nan(int[] result) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   115
        float f1 = FLOAT_NAN;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   116
        float f2 = Float.NaN;
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   117
        result[0] = Float.floatToRawIntBits(f1);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   118
        result[1] = Float.floatToRawIntBits(f2);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   119
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   120
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   121
    // Check doubles.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   122
    static void check_double(long[] result, double d1, double d2) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   123
        if (result[0] == result[1]) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   124
            throw new RuntimeException("ERROR: Two different double values are considered equal. \n"
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   125
                                       + String.format("\toriginal values: 0x%x 0x%x\n", Double.doubleToRawLongBits(d1), Double.doubleToRawLongBits(d2))
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   126
                                       + String.format("\tvalues after execution of method test(): 0x%x 0x%x", result[0], result[1]));
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   127
        }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   128
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   129
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   130
    // Check floats.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   131
    static void check_float(int[] result, float f1, float f2) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   132
        if (result[0] == result[1]) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   133
            throw new RuntimeException("ERROR: Two different float values are considered equal. \n"
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   134
                                       + String.format("\toriginal values: 0x%x 0x%x\n", Float.floatToRawIntBits(f1), Float.floatToRawIntBits(f2))
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   135
                                       + String.format("\tvalues after execution of method test(): 0x%x 0x%x", result[0], result[1]));
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   136
        }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   137
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   138
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   139
    public static void main(String[] args) {
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   140
        // Float tests.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   141
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   142
        int[] iresult = new int[2];
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   143
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   144
        // -Inf and +Inf.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   145
        test_float_inf(iresult);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   146
        check_float(iresult, FLOAT_MINUS_INF, FLOAT_PLUS_INF);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   147
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   148
        // 0 and -0.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   149
        test_float_zero(iresult);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   150
        check_float(iresult, FLOAT_MINUS_ZERO, 0);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   151
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   152
        // Diferrent NaNs.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   153
        test_float_nan(iresult);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   154
        check_float(iresult, FLOAT_NAN, Float.NaN);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   155
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   156
        // Double tests.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   157
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   158
        long[] lresult = new long[2];
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   159
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   160
        // -Inf and +Inf.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   161
        test_double_inf(lresult);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   162
        check_double(lresult, DOUBLE_MINUS_INF, DOUBLE_PLUS_INF);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   163
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   164
        // 0 and -0.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   165
        test_double_zero(lresult);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   166
        check_double(lresult, DOUBLE_MINUS_ZERO, 0);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   167
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   168
        // Diferrent NaNs.
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   169
        test_double_nan(lresult);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   170
        check_double(lresult, DOUBLE_NAN, Double.NaN);
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   171
    }
46bff23fc1a2 8073670: TypeF::eq and TypeD::eq do not handle NaNs correctly
zmajo
parents:
diff changeset
   172
}