hotspot/test/compiler/floatingpoint/ModNaN.java
author ctornqvi
Thu, 10 Dec 2015 09:42:22 -0800
changeset 35055 a4cf2927e727
parent 30028 ac021a11a31b
child 35179 9e364645fdca
permissions -rw-r--r--
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0) Reviewed-by: coleenp, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24319
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     1
/*
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     4
 *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     7
 * published by the Free Software Foundation.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     8
 *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    13
 * accompanied this code).
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    14
 *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    18
 *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    21
 * questions.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    22
 */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    23
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    24
/**
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    25
 * @test
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    26
 * @bug 8015396
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    27
 * @summary double a%b returns NaN for some (a,b) (|a| < inf, |b|>0) (on Core i7 980X)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    28
 * @run main ModNaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    29
 */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    30
public class ModNaN {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    31
    /* This bug was seen in the field for a particular version of the VM,
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    32
     * but never reproduced internally, and the reason was never known,
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    33
     * nor were the exact circumstances of the failure.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    34
     */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    35
    /*
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    36
     * Failed on Windows 7/Core i7 980X/1.6.0_38 (64-bit):
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    37
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    38
     * NaNs (i.e., when it fails, this is what we expect to see):
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    39
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    40
     * 8.98846567431158E307 % 1.295163E-318 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    41
     * (0x7FE0000000000000L % 0x0000000000040000L)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    42
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    43
     * 1.7976931348623157E308 % 2.59032E-318 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    44
     * (0x7FEFFFFFFFFFFFFFL % 0x000000000007FFFFL)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    45
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    46
     * 1.7976931348623157E308 % 1.060997895E-314 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    47
     * (0x7FEFFFFFFFFFFFFFL % 0x000000007FFFFFFFL)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    48
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    49
     * 1.7976931348623157E308 % 6.767486E-317 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    50
     * (0x7FEFFFFFFFFFFFFFL % 0x0000000000d10208L)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    51
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    52
     * 1.7976931348623157E308 % 7.528725E-318 = NaN
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    53
     * (0x7FEFFFFFFFFFFFFFL % 0x0000000000174077L)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    54
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    55
     * These cases did not fail, even when the previous five did:
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    56
     * 8.98846567431158E307 % 1.29516E-318 = 2.53E-321
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    57
     * (0x7fe0000000000000L % 0x000000000003ffffL)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    58
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    59
     * 1.7976931348623157E308 % 2.590327E-318 = 0.0
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    60
     * (0x7fefffffffffffffL % 0x0000000000080000L)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    61
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    62
     * 1.7976931348623157E308 % 1.060965516E-314 = 9.35818525E-315
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    63
     * (0x7fefffffffffffffL % 0x000000007ffeffffL)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    64
     *
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    65
     */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    66
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    67
    static double[][] bad = new double[][] {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    68
            /*
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    69
             * These hex numbers correspond to the base-10 doubles in the
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    70
             * comment above; this can be checked by observing the output
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    71
             * of testWithPrint.
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    72
             */
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    73
            new double[] { Double.longBitsToDouble(0x7FE0000000000000L),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    74
                    Double.longBitsToDouble(0x0000000000040000L) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    75
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    76
                    Double.longBitsToDouble(0x000000000007FFFFL) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    77
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    78
                    Double.longBitsToDouble(0x000000007FFFFFFFL) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    79
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    80
                    6.767486E-317 },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    81
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    82
                    7.528725E-318 }, };
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    83
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    84
    static double[][] good = new double[][] {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    85
            new double[] { Double.longBitsToDouble(0x7FE0000000000000L),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    86
                    Double.longBitsToDouble(0x000000000003FFFFL) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    87
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    88
                    Double.longBitsToDouble(0x0000000000080000L) },
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    89
            new double[] { Double.longBitsToDouble(0x7FEFFFFFFFFFFFFFL),
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    90
                    Double.longBitsToDouble(0x000000007FFEFFFFL) }, };
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    91
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    92
    public static void main(String[] args) throws InterruptedException {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    93
        int N = 10000;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    94
        testWithPrint();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    95
        for (int i = 0; i < N; i++)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    96
            testStrict();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    97
        for (int i = 0; i < N; i++)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    98
            test();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
    99
        Thread.sleep(1000); // pause to let the compiler work
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   100
        for (int i = 0; i < 10; i++)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   101
            testStrict();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   102
        for (int i = 0; i < 10; i++)
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   103
            test();
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   104
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   105
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   106
    public strictfp static void testWithPrint() {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   107
        for (double[] ab : bad) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   108
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   109
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   110
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   111
            System.out.println("" + a + "("+toHexRep(a)+") mod " +
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   112
                                    b + "("+toHexRep(b)+") yields " +
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   113
                                    mod + "("+toHexRep(mod)+")");
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   114
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   115
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   116
        for (double[] ab : good) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   117
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   118
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   119
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   120
            System.out.println("" + a + "("+toHexRep(a)+") mod " +
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   121
                                    b + "("+toHexRep(b)+") yields " +
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   122
                                    mod + "("+toHexRep(mod)+")");
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   123
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   124
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   125
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   126
    public strictfp static void testStrict() {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   127
        for (double[] ab : bad) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   128
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   129
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   130
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   131
            check(mod);
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   132
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   133
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   134
        for (double[] ab : good) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   135
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   136
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   137
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   138
            check(mod);
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   139
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   140
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   141
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   142
    public static void test() {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   143
        for (double[] ab : bad) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   144
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   145
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   146
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   147
            check(mod);
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   148
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   149
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   150
        for (double[] ab : good) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   151
            double a = ab[0];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   152
            double b = ab[1];
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   153
            double mod = a % b;
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   154
            check(mod);
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   155
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   156
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   157
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   158
    static String toHexRep(double d) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   159
        return "0x" + Long.toHexString(Double.doubleToRawLongBits(d)) + "L";
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   160
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   161
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   162
    static void check(double mod) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   163
        if (Double.isNaN(mod)) {
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   164
            throw new Error("Saw a NaN, fail");
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   165
        }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   166
    }
457a79645387 8039407: Regression test needed for JDK-8015396
drchase
parents:
diff changeset
   167
}