test/jdk/java/lang/Math/DivModTests.java
author redestad
Wed, 10 Apr 2019 20:03:07 +0200
changeset 54492 9d0ae9508d53
parent 47216 71c04702a3d5
permissions -rw-r--r--
8222029: Optimize Math.floorMod Reviewed-by: aph, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
     1
/*
38455
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
     2
 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
     4
 *
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
     8
 *
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    13
 * accompanied this code).
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    14
 *
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    18
 *
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    21
 * questions.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    22
 */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    23
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    24
import java.math.BigDecimal;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    25
import java.math.RoundingMode;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    26
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    27
/**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    28
 * @test Test Math and StrictMath Floor Div / Modulo operations.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    29
 * @bug 6282196
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    30
 * @summary Basic tests for Floor division and modulo methods for both Math
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    31
 * and StrictMath for int and long datatypes.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    32
 */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    33
public class DivModTests {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    34
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    35
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    36
     * The count of test errors.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    37
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    38
    private static int errors = 0;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    39
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    40
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    41
     * @param args the command line arguments are unused
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    42
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    43
    public static void main(String[] args) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    44
        errors = 0;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    45
        testIntFloorDivMod();
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    46
        testLongFloorDivMod();
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    47
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    48
        if (errors > 0) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    49
            throw new RuntimeException(errors + " errors found in DivMod methods.");
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    50
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    51
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    52
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    53
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    54
     * Report a test failure and increment the error count.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    55
     * @param message the formatting string
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    56
     * @param args the variable number of arguments for the message.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    57
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    58
    static void fail(String message, Object... args) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    59
        errors++;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    60
        System.out.printf(message, args);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    61
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    62
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    63
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    64
     * Test the integer floorDiv and floorMod methods.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    65
     * Math and StrictMath tested and the same results are expected for both.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    66
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    67
    static void testIntFloorDivMod() {
14703
84efc7a1216e 8004066: TEST_BUG: test/java/lang/Math/DivModTests.java assumes ArithmeticException message
kmo
parents: 14420
diff changeset
    68
        testIntFloorDivMod(4, 0, new ArithmeticException(), new ArithmeticException()); // Should throw ArithmeticException
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    69
        testIntFloorDivMod(4, 3, 1, 1);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    70
        testIntFloorDivMod(3, 3, 1, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    71
        testIntFloorDivMod(2, 3, 0, 2);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    72
        testIntFloorDivMod(1, 3, 0, 1);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    73
        testIntFloorDivMod(0, 3, 0, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    74
        testIntFloorDivMod(4, -3, -2, -2);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    75
        testIntFloorDivMod(3, -3, -1, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    76
        testIntFloorDivMod(2, -3, -1, -1);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    77
        testIntFloorDivMod(1, -3, -1, -2);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    78
        testIntFloorDivMod(0, -3, 0, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    79
        testIntFloorDivMod(-1, 3, -1, 2);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    80
        testIntFloorDivMod(-2, 3, -1, 1);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    81
        testIntFloorDivMod(-3, 3, -1, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    82
        testIntFloorDivMod(-4, 3, -2, 2);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    83
        testIntFloorDivMod(-1, -3, 0, -1);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    84
        testIntFloorDivMod(-2, -3, 0, -2);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    85
        testIntFloorDivMod(-3, -3, 1, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    86
        testIntFloorDivMod(-4, -3, 1, -1);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    87
        testIntFloorDivMod(Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    88
        testIntFloorDivMod(Integer.MAX_VALUE, -1, -Integer.MAX_VALUE, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    89
        testIntFloorDivMod(Integer.MAX_VALUE, 3, 715827882, 1);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    90
        testIntFloorDivMod(Integer.MAX_VALUE - 1, 3, 715827882, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    91
        testIntFloorDivMod(Integer.MIN_VALUE, 3, -715827883, 1);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    92
        testIntFloorDivMod(Integer.MIN_VALUE + 1, 3, -715827883, 2);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    93
        testIntFloorDivMod(Integer.MIN_VALUE + 1, -1, Integer.MAX_VALUE, 0);
54492
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
    94
        testIntFloorDivMod(Integer.MAX_VALUE, Integer.MAX_VALUE, 1, 0);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
    95
        testIntFloorDivMod(Integer.MAX_VALUE, Integer.MIN_VALUE, -1, -1);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
    96
        testIntFloorDivMod(Integer.MIN_VALUE, Integer.MIN_VALUE, 1, 0);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
    97
        testIntFloorDivMod(Integer.MIN_VALUE, Integer.MAX_VALUE, -2, 2147483646);
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    98
        // Special case of integer overflow
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
    99
        testIntFloorDivMod(Integer.MIN_VALUE, -1, Integer.MIN_VALUE, 0);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   100
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   101
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   102
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   103
     * Test FloorDiv and then FloorMod with int data.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   104
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   105
    static void testIntFloorDivMod(int x, int y, Object divExpected, Object modExpected) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   106
        testIntFloorDiv(x, y, divExpected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   107
        testIntFloorMod(x, y, modExpected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   108
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   109
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   110
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   111
     * Test FloorDiv with int data.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   112
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   113
    static void testIntFloorDiv(int x, int y, Object expected) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   114
        Object result = doFloorDiv(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   115
        if (!resultEquals(result, expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   116
            fail("FAIL: Math.floorDiv(%d, %d) = %s; expected %s%n", x, y, result, expected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   117
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   118
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   119
        Object strict_result = doStrictFloorDiv(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   120
        if (!resultEquals(strict_result, expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   121
            fail("FAIL: StrictMath.floorDiv(%d, %d) = %s; expected %s%n", x, y, strict_result, expected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   122
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   123
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   124
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   125
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   126
     * Test FloorMod with int data.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   127
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   128
    static void testIntFloorMod(int x, int y, Object expected) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   129
        Object result = doFloorMod(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   130
        if (!resultEquals(result, expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   131
            fail("FAIL: Math.floorMod(%d, %d) = %s; expected %s%n", x, y, result, expected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   132
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   133
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   134
        Object strict_result = doStrictFloorMod(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   135
        if (!resultEquals(strict_result, expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   136
            fail("FAIL: StrictMath.floorMod(%d, %d) = %s; expected %s%n", x, y, strict_result, expected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   137
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   138
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   139
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   140
            // Verify result against double precision floor function
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   141
            int tmp = x / y;     // Force ArithmeticException for divide by zero
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   142
            double ff = x - Math.floor((double)x / (double)y) * y;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   143
            int fr = (int)ff;
17453
1de0e7df9a90 8014296: DivModTests should not compare pointers
rriggs
parents: 14703
diff changeset
   144
            boolean t = (fr == ((Integer)result));
1de0e7df9a90 8014296: DivModTests should not compare pointers
rriggs
parents: 14703
diff changeset
   145
            if (!result.equals(fr)) {
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   146
                fail("FAIL: Math.floorMod(%d, %d) = %s differs from Math.floor(x, y): %d%n", x, y, result, fr);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   147
            }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   148
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   149
            if (y != 0) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   150
                fail("FAIL: Math.floorMod(%d, %d); unexpected %s%n", x, y, ae);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   151
            }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   152
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   153
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   154
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   155
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   156
     * Test the floorDiv and floorMod methods for primitive long.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   157
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   158
    static void testLongFloorDivMod() {
14703
84efc7a1216e 8004066: TEST_BUG: test/java/lang/Math/DivModTests.java assumes ArithmeticException message
kmo
parents: 14420
diff changeset
   159
        testLongFloorDivMod(4L, 0L, new ArithmeticException(), new ArithmeticException()); // Should throw ArithmeticException
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   160
        testLongFloorDivMod(4L, 3L, 1L, 1L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   161
        testLongFloorDivMod(3L, 3L, 1L, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   162
        testLongFloorDivMod(2L, 3L, 0L, 2L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   163
        testLongFloorDivMod(1L, 3L, 0L, 1L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   164
        testLongFloorDivMod(0L, 3L, 0L, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   165
        testLongFloorDivMod(4L, -3L, -2L, -2L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   166
        testLongFloorDivMod(3L, -3L, -1L, 0l);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   167
        testLongFloorDivMod(2L, -3L, -1L, -1L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   168
        testLongFloorDivMod(1L, -3L, -1L, -2L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   169
        testLongFloorDivMod(0L, -3L, 0L, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   170
        testLongFloorDivMod(-1L, 3L, -1L, 2L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   171
        testLongFloorDivMod(-2L, 3L, -1L, 1L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   172
        testLongFloorDivMod(-3L, 3L, -1L, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   173
        testLongFloorDivMod(-4L, 3L, -2L, 2L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   174
        testLongFloorDivMod(-1L, -3L, 0L, -1L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   175
        testLongFloorDivMod(-2L, -3L, 0L, -2L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   176
        testLongFloorDivMod(-3L, -3L, 1L, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   177
        testLongFloorDivMod(-4L, -3L, 1L, -1L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   178
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   179
        testLongFloorDivMod(Long.MAX_VALUE, 1, Long.MAX_VALUE, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   180
        testLongFloorDivMod(Long.MAX_VALUE, -1, -Long.MAX_VALUE, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   181
        testLongFloorDivMod(Long.MAX_VALUE, 3L, Long.MAX_VALUE / 3L, 1L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   182
        testLongFloorDivMod(Long.MAX_VALUE - 1L, 3L, (Long.MAX_VALUE - 1L) / 3L, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   183
        testLongFloorDivMod(Long.MIN_VALUE, 3L, Long.MIN_VALUE / 3L - 1L, 1L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   184
        testLongFloorDivMod(Long.MIN_VALUE + 1L, 3L, Long.MIN_VALUE / 3L - 1L, 2L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   185
        testLongFloorDivMod(Long.MIN_VALUE + 1, -1, Long.MAX_VALUE, 0L);
54492
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
   186
        testLongFloorDivMod(Long.MAX_VALUE, Long.MAX_VALUE, 1L, 0L);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
   187
        testLongFloorDivMod(Long.MAX_VALUE, Long.MIN_VALUE, -1L, -1L);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
   188
        testLongFloorDivMod(Long.MIN_VALUE, Long.MIN_VALUE, 1L, 0L);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
   189
        testLongFloorDivMod(Long.MIN_VALUE, Long.MAX_VALUE, -2L, 9223372036854775806L);
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   190
        // Special case of integer overflow
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   191
        testLongFloorDivMod(Long.MIN_VALUE, -1, Long.MIN_VALUE, 0L);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   192
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   193
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   194
    /**
38455
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   195
     * Test the long floorDiv and floorMod methods.
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   196
     * Math and StrictMath are tested and the same results are expected for both.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   197
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   198
    static void testLongFloorDivMod(long x, long y, Object divExpected, Object modExpected) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   199
        testLongFloorDiv(x, y, divExpected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   200
        testLongFloorMod(x, y, modExpected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   201
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   202
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   203
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   204
     * Test FloorDiv with long arguments against expected value.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   205
     * The expected value is usually a Long but in some cases  is
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   206
     * an ArithmeticException.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   207
     *
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   208
     * @param x dividend
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   209
     * @param y modulus
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   210
     * @param expected expected value,
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   211
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   212
    static void testLongFloorDiv(long x, long y, Object expected) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   213
        Object result = doFloorDiv(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   214
        if (!resultEquals(result, expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   215
            fail("FAIL: long Math.floorDiv(%d, %d) = %s; expected %s%n", x, y, result, expected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   216
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   217
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   218
        Object strict_result = doStrictFloorDiv(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   219
        if (!resultEquals(strict_result, expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   220
            fail("FAIL: long StrictMath.floorDiv(%d, %d) = %s; expected %s%n", x, y, strict_result, expected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   221
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   222
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   223
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   224
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   225
     * Test FloorMod of long arguments against expected value.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   226
     * The expected value is usually a Long but in some cases  is
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   227
     * an ArithmeticException.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   228
     *
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   229
     * @param x dividend
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   230
     * @param y modulus
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   231
     * @param expected expected value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   232
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   233
    static void testLongFloorMod(long x, long y, Object expected) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   234
        Object result = doFloorMod(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   235
        if (!resultEquals(result, expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   236
            fail("FAIL: long Math.floorMod(%d, %d) = %s; expected %s%n", x, y, result, expected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   237
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   238
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   239
        Object strict_result = doStrictFloorMod(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   240
        if (!resultEquals(strict_result, expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   241
            fail("FAIL: long StrictMath.floorMod(%d, %d) = %s; expected %s%n", x, y, strict_result, expected);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   242
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   243
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   244
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   245
            // Verify the result against BigDecimal rounding mode.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   246
            BigDecimal xD = new BigDecimal(x);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   247
            BigDecimal yD = new BigDecimal(y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   248
            BigDecimal resultD = xD.divide(yD, RoundingMode.FLOOR);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   249
            resultD = resultD.multiply(yD);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   250
            resultD = xD.subtract(resultD);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   251
            long fr = resultD.longValue();
17453
1de0e7df9a90 8014296: DivModTests should not compare pointers
rriggs
parents: 14703
diff changeset
   252
            if (!result.equals(fr)) {
1de0e7df9a90 8014296: DivModTests should not compare pointers
rriggs
parents: 14703
diff changeset
   253
                fail("FAIL: Long.floorMod(%d, %d) = %d is different than BigDecimal result: %d%n", x, y, result, fr);
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   254
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   255
            }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   256
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   257
            if (y != 0) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   258
                fail("FAIL: long Math.floorMod(%d, %d); unexpected ArithmeticException from bigdecimal");
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   259
            }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   260
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   261
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   262
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   263
    /**
38455
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   264
     * Test the floorDiv and floorMod methods for mixed long and int.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   265
     */
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   266
    static void testLongIntFloorDivMod() {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   267
        testLongIntFloorDivMod(4L, 0, new ArithmeticException(), new ArithmeticException()); // Should throw ArithmeticException
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   268
        testLongIntFloorDivMod(4L, 3, 1L, 1);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   269
        testLongIntFloorDivMod(3L, 3, 1L, 0);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   270
        testLongIntFloorDivMod(2L, 3, 0L, 2);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   271
        testLongIntFloorDivMod(1L, 3, 0L, 1);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   272
        testLongIntFloorDivMod(0L, 3, 0L, 0);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   273
        testLongIntFloorDivMod(4L, -3, -2L, -2);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   274
        testLongIntFloorDivMod(3L, -3, -1L, 0);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   275
        testLongIntFloorDivMod(2L, -3, -1L, -1);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   276
        testLongIntFloorDivMod(1L, -3, -1L, -2);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   277
        testLongIntFloorDivMod(0L, -3, 0L, 0);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   278
        testLongIntFloorDivMod(-1L, 3, -1L, 2);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   279
        testLongIntFloorDivMod(-2L, 3, -1L, 1);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   280
        testLongIntFloorDivMod(-3L, 3, -1L, 0);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   281
        testLongIntFloorDivMod(-4L, 3, -2L, 2);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   282
        testLongIntFloorDivMod(-1L, -3, 0L, -1);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   283
        testLongIntFloorDivMod(-2L, -3, 0L, -2);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   284
        testLongIntFloorDivMod(-3L, -3, 1L, 0);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   285
        testLongIntFloorDivMod(-4L, -3, 1L, -1);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   286
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   287
        testLongIntFloorDivMod(Long.MAX_VALUE, 1, Long.MAX_VALUE, 0L);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   288
        testLongIntFloorDivMod(Long.MAX_VALUE, -1, -Long.MAX_VALUE, 0L);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   289
        testLongIntFloorDivMod(Long.MAX_VALUE, 3, Long.MAX_VALUE / 3L, 1L);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   290
        testLongIntFloorDivMod(Long.MAX_VALUE - 1L, 3, (Long.MAX_VALUE - 1L) / 3L, 0L);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   291
        testLongIntFloorDivMod(Long.MIN_VALUE, 3, Long.MIN_VALUE / 3L - 1L, 1L);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   292
        testLongIntFloorDivMod(Long.MIN_VALUE + 1L, 3, Long.MIN_VALUE / 3L - 1L, 2L);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   293
        testLongIntFloorDivMod(Long.MIN_VALUE + 1, -1, Long.MAX_VALUE, 0L);
54492
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
   294
        testLongIntFloorDivMod(Long.MAX_VALUE, Integer.MAX_VALUE, 4294967298L, 1);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
   295
        testLongIntFloorDivMod(Long.MAX_VALUE, Integer.MIN_VALUE, -4294967296L, -1);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
   296
        testLongIntFloorDivMod(Long.MIN_VALUE, Integer.MIN_VALUE, 4294967296L, 0);
9d0ae9508d53 8222029: Optimize Math.floorMod
redestad
parents: 47216
diff changeset
   297
        testLongIntFloorDivMod(Long.MIN_VALUE, Integer.MAX_VALUE, -4294967299L, 2147483645);
38455
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   298
        // Special case of integer overflow
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   299
        testLongIntFloorDivMod(Long.MIN_VALUE, -1, Long.MIN_VALUE, 0L);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   300
    }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   301
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   302
    /**
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   303
     * Test the integer floorDiv and floorMod methods.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   304
     * Math and StrictMath are tested and the same results are expected for both.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   305
     */
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   306
    static void testLongIntFloorDivMod(long x, int y, Object divExpected, Object modExpected) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   307
        testLongIntFloorDiv(x, y, divExpected);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   308
        testLongIntFloorMod(x, y, modExpected);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   309
    }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   310
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   311
    /**
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   312
     * Test FloorDiv with long arguments against expected value.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   313
     * The expected value is usually a Long but in some cases  is
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   314
     * an ArithmeticException.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   315
     *
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   316
     * @param x dividend
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   317
     * @param y modulus
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   318
     * @param expected expected value,
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   319
     */
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   320
    static void testLongIntFloorDiv(long x, int y, Object expected) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   321
        Object result = doFloorDiv(x, y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   322
        if (!resultEquals(result, expected)) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   323
            fail("FAIL: long Math.floorDiv(%d, %d) = %s; expected %s%n", x, y, result, expected);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   324
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   325
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   326
        Object strict_result = doStrictFloorDiv(x, y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   327
        if (!resultEquals(strict_result, expected)) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   328
            fail("FAIL: long StrictMath.floorDiv(%d, %d) = %s; expected %s%n", x, y, strict_result, expected);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   329
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   330
    }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   331
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   332
    /**
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   333
     * Test FloorMod of long arguments against expected value.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   334
     * The expected value is usually a Long but in some cases  is
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   335
     * an ArithmeticException.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   336
     *
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   337
     * @param x dividend
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   338
     * @param y modulus
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   339
     * @param expected expected value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   340
     */
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   341
    static void testLongIntFloorMod(long x, int y, Object expected) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   342
        Object result = doFloorMod(x, y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   343
        if (!resultEquals(result, expected)) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   344
            fail("FAIL: long Math.floorMod(%d, %d) = %s; expected %s%n", x, y, result, expected);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   345
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   346
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   347
        Object strict_result = doStrictFloorMod(x, y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   348
        if (!resultEquals(strict_result, expected)) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   349
            fail("FAIL: long StrictMath.floorMod(%d, %d) = %s; expected %s%n", x, y, strict_result, expected);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   350
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   351
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   352
        try {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   353
            // Verify the result against BigDecimal rounding mode.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   354
            BigDecimal xD = new BigDecimal(x);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   355
            BigDecimal yD = new BigDecimal(y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   356
            BigDecimal resultD = xD.divide(yD, RoundingMode.FLOOR);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   357
            resultD = resultD.multiply(yD);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   358
            resultD = xD.subtract(resultD);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   359
            long fr = resultD.longValue();
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   360
            if (!result.equals(fr)) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   361
                fail("FAIL: Long.floorMod(%d, %d) = %d is different than BigDecimal result: %d%n", x, y, result, fr);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   362
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   363
            }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   364
        } catch (ArithmeticException ae) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   365
            if (y != 0) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   366
                fail("FAIL: long Math.floorMod(%d, %d); unexpected ArithmeticException from bigdecimal");
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   367
            }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   368
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   369
    }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   370
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   371
    /**
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   372
     * Invoke floorDiv and return the result or any exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   373
     * @param x the x value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   374
     * @param y the y value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   375
     * @return the result Integer or an exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   376
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   377
    static Object doFloorDiv(int x, int y) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   378
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   379
            return Math.floorDiv(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   380
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   381
            return ae;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   382
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   383
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   384
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   385
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   386
     * Invoke floorDiv and return the result or any exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   387
     * @param x the x value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   388
     * @param y the y value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   389
     * @return the result Integer or an exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   390
     */
38455
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   391
    static Object doFloorDiv(long x, int y) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   392
        try {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   393
            return Math.floorDiv(x, y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   394
        } catch (ArithmeticException ae) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   395
            return ae;
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   396
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   397
    }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   398
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   399
    /**
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   400
     * Invoke floorDiv and return the result or any exception.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   401
     * @param x the x value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   402
     * @param y the y value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   403
     * @return the result Integer or an exception.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   404
     */
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   405
    static Object doFloorDiv(long x, long y) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   406
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   407
            return Math.floorDiv(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   408
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   409
            return ae;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   410
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   411
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   412
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   413
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   414
     * Invoke floorDiv and return the result or any exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   415
     * @param x the x value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   416
     * @param y the y value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   417
     * @return the result Integer or an exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   418
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   419
    static Object doFloorMod(int x, int y) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   420
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   421
            return Math.floorMod(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   422
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   423
            return ae;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   424
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   425
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   426
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   427
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   428
     * Invoke floorDiv and return the result or any exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   429
     * @param x the x value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   430
     * @param y the y value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   431
     * @return the result Integer or an exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   432
     */
38455
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   433
    static Object doFloorMod(long x, int y) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   434
        try {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   435
            return Math.floorMod(x, y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   436
        } catch (ArithmeticException ae) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   437
            return ae;
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   438
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   439
    }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   440
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   441
    /**
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   442
     * Invoke floorDiv and return the result or any exception.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   443
     * @param x the x value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   444
     * @param y the y value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   445
     * @return the result Integer or an exception.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   446
     */
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   447
    static Object doFloorMod(long x, long y) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   448
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   449
            return Math.floorMod(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   450
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   451
            return ae;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   452
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   453
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   454
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   455
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   456
     * Invoke floorDiv and return the result or any exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   457
     * @param x the x value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   458
     * @param y the y value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   459
     * @return the result Integer or an exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   460
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   461
    static Object doStrictFloorDiv(int x, int y) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   462
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   463
            return StrictMath.floorDiv(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   464
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   465
            return ae;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   466
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   467
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   468
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   469
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   470
     * Invoke floorDiv and return the result or any exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   471
     * @param x the x value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   472
     * @param y the y value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   473
     * @return the result Integer or an exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   474
     */
38455
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   475
    static Object doStrictFloorDiv(long x, int y) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   476
        try {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   477
            return StrictMath.floorDiv(x, y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   478
        } catch (ArithmeticException ae) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   479
            return ae;
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   480
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   481
    }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   482
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   483
    /**
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   484
     * Invoke floorDiv and return the result or any exception.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   485
     * @param x the x value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   486
     * @param y the y value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   487
     * @return the result Integer or an exception.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   488
     */
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   489
    static Object doStrictFloorDiv(long x, long y) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   490
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   491
            return StrictMath.floorDiv(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   492
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   493
            return ae;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   494
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   495
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   496
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   497
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   498
     * Invoke floorDiv and return the result or any exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   499
     * @param x the x value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   500
     * @param y the y value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   501
     * @return the result Integer or an exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   502
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   503
    static Object doStrictFloorMod(int x, int y) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   504
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   505
            return StrictMath.floorMod(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   506
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   507
            return ae;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   508
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   509
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   510
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   511
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   512
     * Invoke floorDiv and return the result or any exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   513
     * @param x the x value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   514
     * @param y the y value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   515
     * @return the result Integer or an exception.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   516
     */
38455
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   517
    static Object doStrictFloorMod(long x, int y) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   518
        try {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   519
            return StrictMath.floorMod(x, y);
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   520
        } catch (ArithmeticException ae) {
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   521
            return ae;
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   522
        }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   523
    }
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   524
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   525
    /**
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   526
     * Invoke floorDiv and return the result or any exception.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   527
     * @param x the x value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   528
     * @param y the y value
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   529
     * @return the result Integer or an exception.
43fec67d51a3 8023217: Additional floorDiv/floorMod/multiplyExact methods for java.lang.Math
bpb
parents: 17453
diff changeset
   530
     */
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   531
    static Object doStrictFloorMod(long x, long y) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   532
        try {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   533
            return StrictMath.floorMod(x, y);
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   534
        } catch (ArithmeticException ae) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   535
            return ae;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   536
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   537
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   538
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   539
    /**
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   540
     * Returns a boolean by comparing the result and the expected value.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   541
     * The equals method is not defined for ArithmeticException but it is
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   542
     * desirable to have equals return true if the expected and the result
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   543
     * both threw the same exception (class and message.)
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   544
     *
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   545
     * @param result the result from testing the method
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   546
     * @param expected the expected value
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   547
     * @return true if the result is equal to the expected values; false otherwise.
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   548
     */
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   549
    static boolean resultEquals(Object result, Object expected) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   550
        if (result.getClass() != expected.getClass()) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   551
            fail("FAIL: Result type mismatch, %s; expected: %s%n",
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   552
                    result.getClass().getName(), expected.getClass().getName());
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   553
            return false;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   554
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   555
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   556
        if (result.equals(expected)) {
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   557
            return true;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   558
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   559
        // Handle special case to compare ArithmeticExceptions
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   560
        if (result instanceof ArithmeticException && expected instanceof ArithmeticException) {
14703
84efc7a1216e 8004066: TEST_BUG: test/java/lang/Math/DivModTests.java assumes ArithmeticException message
kmo
parents: 14420
diff changeset
   561
            return true;
14420
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   562
        }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   563
        return false;
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   564
    }
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   565
5cbeeccf4a40 6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff changeset
   566
}