Merge "Port OpenJDK8 java.lang functional util methods"
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/MathTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/MathTest.java
index f5bb134..37f5c0a 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/MathTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/MathTest.java
@@ -1057,6 +1057,68 @@
}
/**
+ * {@link java.lang.Math#nextDown(double)}
+ * @since 1.8
+ */
+ @SuppressWarnings("boxing")
+ public void test_nextDown_D() {
+ // This method is semantically equivalent to nextAfter(d,
+ // Double.NEGATIVE_INFINITY),
+ // so we use the data of test_nextAfter_DD
+ for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
+ final double start = NEXTAFTER_DD_START_CASES[i][0];
+ final long nextDownBits = Double
+ .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][2]);
+ final long resultBits = Double.doubleToLongBits(Math.nextDown(start));
+ assertEquals("Result should be next down-number.", nextDownBits,
+ resultBits);
+ }
+
+ // test for cases with NaN
+ assertTrue("The result should be NaN.", Double.isNaN(Math
+ .nextDown(Double.NaN)));
+
+ // test for exception
+ try {
+ Math.nextDown((Double) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+ }
+
+ /**
+ * {@link java.lang.Math#nextDown(float)}
+ * @since 1.8
+ */
+ @SuppressWarnings("boxing")
+ public void test_nextDown_F() {
+ // This method is semantically equivalent to nextAfter(f,
+ // Float.NEGATIVE_INFINITY),
+ // so we use the data of test_nextAfter_FD
+ for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
+ final float start = NEXTAFTER_FD_START_CASES[i][0];
+ final int nextDownBits = Float
+ .floatToIntBits(NEXTAFTER_FD_START_CASES[i][2]);
+ final int resultBits = Float.floatToIntBits(Math.nextDown(start));
+ assertEquals("Result should be next down-number.", nextDownBits,
+ resultBits);
+ }
+
+ // test for cases with NaN
+ assertTrue("The result should be NaN.", Float.isNaN(Math
+ .nextDown(Float.NaN)));
+
+ // test for exception
+ try {
+ Math.nextDown((Float) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+ }
+
+ /**
* java.lang.Math#pow(double, double)
*/
public void test_powDD() {
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/StrictMathTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/StrictMathTest.java
index cce8935..055fbfe 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/StrictMathTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/StrictMathTest.java
@@ -881,6 +881,70 @@
}
/**
+ * {@link java.lang.StrictMath#nextDown(double)}
+ * @since 1.8
+ */
+ @SuppressWarnings("boxing")
+ public void test_nextDown_D() {
+ // This method is semantically equivalent to nextAfter(d,
+ // Double.NEGATIVE_INFINITY),
+ // so we use the data of test_nextAfter_DD
+ for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
+ final double start = NEXTAFTER_DD_START_CASES[i][0];
+ final long nextDownBits = Double
+ .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][2]);
+ final long resultBits = Double.doubleToLongBits(StrictMath
+ .nextDown(start));
+ assertEquals("Result should be next down-number.", nextDownBits,
+ resultBits);
+ }
+
+ // test for cases with NaN
+ assertTrue("The result should be NaN.", Double.isNaN(StrictMath
+ .nextDown(Double.NaN)));
+
+ // test for exception
+ try {
+ StrictMath.nextDown((Double) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+ }
+
+ /**
+ * {@link java.lang.StrictMath#nextDown(float)}
+ * @since 1.8
+ */
+ @SuppressWarnings("boxing")
+ public void test_nextDown_F() {
+ // This method is semantically equivalent to nextAfter(f,
+ // Float.NEGATIVE_INFINITY),
+ // so we use the data of test_nextAfter_FD
+ for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
+ final float start = NEXTAFTER_FD_START_CASES[i][0];
+ final int nextDownBits = Float
+ .floatToIntBits(NEXTAFTER_FD_START_CASES[i][2]);
+ final int resultBits = Float.floatToIntBits(StrictMath
+ .nextDown(start));
+ assertEquals("Result should be next down-number.", nextDownBits,
+ resultBits);
+ }
+
+ // test for cases with NaN
+ assertTrue("The result should be NaN.", Float.isNaN(StrictMath
+ .nextDown(Float.NaN)));
+
+ // test for exception
+ try {
+ StrictMath.nextDown((Float) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+ }
+
+ /**
* java.lang.StrictMath#pow(double, double)
*/
public void test_powDD() {
diff --git a/luni/src/test/java/libcore/java/lang/BooleanTest.java b/luni/src/test/java/libcore/java/lang/BooleanTest.java
index b1f536f..10dac92 100644
--- a/luni/src/test/java/libcore/java/lang/BooleanTest.java
+++ b/luni/src/test/java/libcore/java/lang/BooleanTest.java
@@ -38,4 +38,25 @@
assertEquals(Boolean.TRUE.hashCode(), Boolean.hashCode(true));
assertEquals(Boolean.FALSE.hashCode(), Boolean.hashCode(false));
}
+
+ public void testLogicalAnd() {
+ assertTrue(Boolean.logicalAnd(Boolean.TRUE, Boolean.TRUE));
+ assertFalse(Boolean.logicalAnd(Boolean.TRUE, Boolean.FALSE));
+ assertFalse(Boolean.logicalAnd(Boolean.FALSE, Boolean.TRUE));
+ assertFalse(Boolean.logicalAnd(Boolean.FALSE, Boolean.FALSE));
+ }
+
+ public void testLogicalOr() {
+ assertTrue(Boolean.logicalOr(Boolean.TRUE, Boolean.TRUE));
+ assertTrue(Boolean.logicalOr(Boolean.TRUE, Boolean.FALSE));
+ assertTrue(Boolean.logicalOr(Boolean.FALSE, Boolean.TRUE));
+ assertFalse(Boolean.logicalOr(Boolean.FALSE, Boolean.FALSE));
+ }
+
+ public void testLogicalXor() {
+ assertFalse(Boolean.logicalXor(Boolean.TRUE, Boolean.TRUE));
+ assertTrue(Boolean.logicalXor(Boolean.TRUE, Boolean.FALSE));
+ assertTrue(Boolean.logicalXor(Boolean.FALSE, Boolean.TRUE));
+ assertFalse(Boolean.logicalXor(Boolean.FALSE, Boolean.FALSE));
+ }
}
diff --git a/luni/src/test/java/libcore/java/lang/MathTest.java b/luni/src/test/java/libcore/java/lang/MathTest.java
new file mode 100644
index 0000000..f7ebaa6
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/MathTest.java
@@ -0,0 +1,303 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+import java.math.BigInteger;
+
+public class MathTest extends TestCase {
+
+ public void testIntExact() {
+ testIntExact(123, 456);
+ testIntExact(-456, 456);
+ testIntExact(0, 0);
+ testIntExact(Integer.MAX_VALUE, 1);
+ testIntExact(Integer.MAX_VALUE, -1);
+ testIntExact(Integer.MIN_VALUE, 1);
+ testIntExact(Integer.MIN_VALUE, -1);
+ testIntExact(Integer.MAX_VALUE, Integer.MAX_VALUE);
+ testIntExact(Integer.MIN_VALUE, Integer.MIN_VALUE);
+ }
+
+ private void testIntExact(int a, int b) {
+ testAddExactI(a, b);
+ testSubtractExactI(a, b);
+ testMultiplyExactI(a, b);
+ testIncrementExactI(a);
+ testDecrementExactI(a);
+ testNegateExactI(a);
+ }
+
+ private void testAddExactI(int a, int b) {
+ long expected = (long) a + (long) b;
+ try {
+ assertEquals(expected, Math.addExact(a, b));
+ } catch (ArithmeticException e) {
+ if (expected == a + b) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testSubtractExactI(int a, int b) {
+ long expected = (long) a - (long) b;
+ try {
+ assertEquals(expected, Math.subtractExact(a, b));
+ } catch (ArithmeticException e) {
+ long result = (long) a - (long) b;
+ if (expected == a - b) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testMultiplyExactI(int a, int b) {
+ long expected = (long) a * (long) b;
+ try {
+ assertEquals(expected, Math.multiplyExact(a, b));
+ } catch (ArithmeticException e) {
+ if (expected == a * b) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testIncrementExactI(int a) {
+ long expected = (long) a + 1L;
+ try {
+ assertEquals(expected, Math.incrementExact(a));
+ } catch (ArithmeticException e) {
+ if (expected == a + 1) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testDecrementExactI(int a) {
+ long expected = (long) a - 1L;
+ try {
+ assertEquals(expected, Math.decrementExact(a));
+ } catch (ArithmeticException e) {
+ if (expected == a - 1) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testNegateExactI(int a) {
+ long expected = -((long) a);
+ try {
+ assertEquals(expected, Math.negateExact(a));
+ } catch (ArithmeticException e) {
+ if (expected == -a) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ public void testLongExact() {
+ testLongExact(123, 456);
+ testLongExact(-456, 456);
+ testLongExact(0, 0);
+ testLongExact(Long.MAX_VALUE, 1);
+ testLongExact(Long.MAX_VALUE, -1);
+ testLongExact(Long.MIN_VALUE, 1);
+ testLongExact(Long.MIN_VALUE, -1);
+ testLongExact(Long.MAX_VALUE, Long.MAX_VALUE);
+ testLongExact(Long.MIN_VALUE, Long.MIN_VALUE);
+ }
+
+ private void testLongExact(long a, long b) {
+ testAddExactL(a, b);
+ testSubtractExactL(a, b);
+ testMultiplyExactL(a, b);
+ testIncrementExactL(a);
+ testDecrementExactL(a);
+ testNegateExactL(a);
+ testToIntExactL(a);
+ }
+
+ private void testAddExactL(long a, long b) {
+ BigInteger expected = BigInteger.valueOf(a).add(BigInteger.valueOf(b));
+ try {
+ assertEquals(expected, BigInteger.valueOf(Math.addExact(a, b)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(a + b))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testSubtractExactL(long a, long b) {
+ BigInteger expected = BigInteger.valueOf(a).subtract(BigInteger.valueOf(b));
+ try {
+ assertEquals(expected, BigInteger.valueOf(Math.subtractExact(a, b)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(a - b))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testMultiplyExactL(long a, long b) {
+ BigInteger expected = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b));
+ try {
+ assertEquals(expected, BigInteger.valueOf(Math.multiplyExact(a, b)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(a * b))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testIncrementExactL(long a) {
+ BigInteger expected = BigInteger.valueOf(a).add(BigInteger.ONE);
+ try {
+ assertEquals(expected, BigInteger.valueOf(Math.incrementExact(a)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(a + 1L))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testDecrementExactL(long a) {
+ BigInteger expected = BigInteger.valueOf(a).subtract(BigInteger.ONE);
+ try {
+ assertEquals(expected, BigInteger.valueOf(Math.decrementExact(a)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(a - 1L))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testNegateExactL(long a) {
+ BigInteger expected = BigInteger.valueOf(a).negate();
+ try {
+ assertEquals(expected, BigInteger.valueOf(Math.negateExact(a)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(-a))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testToIntExactL(long a) {
+ try {
+ assertEquals((int) a, Math.toIntExact(a));
+ assertEquals(a, Math.toIntExact(a)); // Is not exact, should throw AE.
+ } catch (ArithmeticException e) {
+ if (a <= Integer.MAX_VALUE && a >= Integer.MIN_VALUE) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ public void testIntFloorDivMod() {
+ testFloorDivModI(123, 456);
+ testFloorDivModI(456, 123);
+ testFloorDivModI(369, 123);
+ testFloorDivModI(1, 0);
+ testFloorDivModI(Integer.MAX_VALUE, 1);
+ testFloorDivModI(Integer.MAX_VALUE, -1);
+ testFloorDivModI(Integer.MIN_VALUE, 1);
+ testFloorDivModI(Integer.MIN_VALUE, -1);
+ }
+
+ private void testFloorDivModI(int a, int b) {
+ testFloorDivI(a, b);
+ testFloorModI(a, b);
+ }
+
+ private void testFloorDivI(int a, int b) {
+ try {
+ int floorDiv = Math.floorDiv(a, b);
+ int expected = a / b;
+ if (expected < 0 && a % b != 0) {
+ --expected;
+ }
+ assertEquals(expected, floorDiv);
+ } catch (ArithmeticException e) {
+ if (b != 0) {
+ fail(); // Should only throw AE when b is zero.
+ }
+ }
+ }
+
+ private void testFloorModI(int a, int b) {
+ try {
+ int floorMod = Math.floorMod(a, b);
+ int expected = a % b;
+ if ((a ^ b) < 0 && expected != 0) {
+ expected = b - expected;
+ }
+ assertEquals(expected, floorMod);
+ } catch (ArithmeticException e) {
+ if (b != 0) {
+ fail(); // Should only throw AE when b is zero.
+ }
+ }
+ }
+
+ public void testLongFloorDivMod() {
+ testFloorDivModL(123L, 456L);
+ testFloorDivModL(456L, 123L);
+ testFloorDivModL(369L, 123L);
+ testFloorDivModL(1L, 0L);
+ testFloorDivModL(Long.MAX_VALUE, 1L);
+ testFloorDivModL(Long.MAX_VALUE, -1L);
+ testFloorDivModL(Long.MIN_VALUE, 1L);
+ testFloorDivModL(Long.MIN_VALUE, -1L);
+ }
+
+ private void testFloorDivModL(long a, long b) {
+ testFloorDivL(a, b);
+ testFloorModL(a, b);
+ }
+
+ private void testFloorDivL(long a, long b) {
+ try {
+ long floorDiv = Math.floorDiv(a, b);
+ long expected = a / b;
+ if (expected < 0 && a % b != 0) {
+ --expected;
+ }
+ assertEquals(expected, floorDiv);
+ } catch (ArithmeticException e) {
+ if (b != 0) {
+ fail(); // Should only throw AE when b is zero.
+ }
+ }
+ }
+
+ private void testFloorModL(long a, long b) {
+ try {
+ long floorMod = Math.floorMod(a, b);
+ long expected = a % b;
+ if ((a ^ b) < 0 && expected != 0) {
+ expected = b - expected;
+ }
+ assertEquals(expected, floorMod);
+ } catch (ArithmeticException e) {
+ if (b != 0) {
+ fail(); // Should only throw AE when b is zero.
+ }
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/StrictMathTest.java b/luni/src/test/java/libcore/java/lang/StrictMathTest.java
new file mode 100644
index 0000000..2509af8
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/StrictMathTest.java
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+import java.math.BigInteger;
+
+public class StrictMathTest extends TestCase {
+
+ public void testIntExact() {
+ testIntExact(123, 456);
+ testIntExact(-456, 456);
+ testIntExact(0, 0);
+ testIntExact(Integer.MAX_VALUE, 1);
+ testIntExact(Integer.MAX_VALUE, -1);
+ testIntExact(Integer.MIN_VALUE, 1);
+ testIntExact(Integer.MIN_VALUE, -1);
+ testIntExact(Integer.MAX_VALUE, Integer.MAX_VALUE);
+ testIntExact(Integer.MIN_VALUE, Integer.MIN_VALUE);
+ }
+
+ private void testIntExact(int a, int b) {
+ testAddExactI(a, b);
+ testSubtractExactI(a, b);
+ testMultiplyExactI(a, b);
+ }
+
+ private void testAddExactI(int a, int b) {
+ long expected = (long) a + (long) b;
+ try {
+ assertEquals(expected, StrictMath.addExact(a, b));
+ } catch (ArithmeticException e) {
+ if (expected == a + b) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testSubtractExactI(int a, int b) {
+ long expected = (long) a - (long) b;
+ try {
+ assertEquals(expected, StrictMath.subtractExact(a, b));
+ } catch (ArithmeticException e) {
+ long result = (long) a - (long) b;
+ if (expected == a - b) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testMultiplyExactI(int a, int b) {
+ long expected = (long) a * (long) b;
+ try {
+ assertEquals(expected, StrictMath.multiplyExact(a, b));
+ } catch (ArithmeticException e) {
+ if (expected == a * b) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ public void testLongExact() {
+ testLongExact(123, 456);
+ testLongExact(-456, 456);
+ testLongExact(0, 0);
+ testLongExact(Long.MAX_VALUE, 1);
+ testLongExact(Long.MAX_VALUE, -1);
+ testLongExact(Long.MIN_VALUE, 1);
+ testLongExact(Long.MIN_VALUE, -1);
+ testLongExact(Long.MAX_VALUE, Long.MAX_VALUE);
+ testLongExact(Long.MIN_VALUE, Long.MIN_VALUE);
+ }
+
+ private void testLongExact(long a, long b) {
+ testAddExactL(a, b);
+ testSubtractExactL(a, b);
+ testMultiplyExactL(a, b);
+ testToIntExactL(a);
+ }
+
+ private void testAddExactL(long a, long b) {
+ BigInteger expected = BigInteger.valueOf(a).add(BigInteger.valueOf(b));
+ try {
+ assertEquals(expected, BigInteger.valueOf(StrictMath.addExact(a, b)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(a + b))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testSubtractExactL(long a, long b) {
+ BigInteger expected = BigInteger.valueOf(a).subtract(BigInteger.valueOf(b));
+ try {
+ assertEquals(expected, BigInteger.valueOf(StrictMath.subtractExact(a, b)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(a - b))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testMultiplyExactL(long a, long b) {
+ BigInteger expected = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b));
+ try {
+ assertEquals(expected, BigInteger.valueOf(StrictMath.multiplyExact(a, b)));
+ } catch (ArithmeticException e) {
+ if (expected.equals(BigInteger.valueOf(a * b))) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ private void testToIntExactL(long a) {
+ try {
+ assertEquals((int) a, StrictMath.toIntExact(a));
+ assertEquals(a, StrictMath.toIntExact(a)); // Is not exact, should throw AE.
+ } catch (ArithmeticException e) {
+ if (a <= Integer.MAX_VALUE && a >= Integer.MIN_VALUE) {
+ fail(); // This is not an overflow
+ }
+ }
+ }
+
+ public void testIntFloorDivMod() {
+ testFloorDivModI(123, 456);
+ testFloorDivModI(456, 123);
+ testFloorDivModI(369, 123);
+ testFloorDivModI(1, 0);
+ testFloorDivModI(Integer.MAX_VALUE, 1);
+ testFloorDivModI(Integer.MAX_VALUE, -1);
+ testFloorDivModI(Integer.MIN_VALUE, 1);
+ testFloorDivModI(Integer.MIN_VALUE, -1);
+ }
+
+ private void testFloorDivModI(int a, int b) {
+ testFloorDivI(a, b);
+ testFloorModI(a, b);
+ }
+
+ private void testFloorDivI(int a, int b) {
+ try {
+ int floorDiv = StrictMath.floorDiv(a, b);
+ int expected = a / b;
+ if (expected < 0 && a % b != 0) {
+ --expected;
+ }
+ assertEquals(expected, floorDiv);
+ } catch (ArithmeticException e) {
+ if (b != 0) {
+ fail(); // Should only throw AE when b is zero.
+ }
+ }
+ }
+
+ private void testFloorModI(int a, int b) {
+ try {
+ int floorMod = StrictMath.floorMod(a, b);
+ int expected = a % b;
+ if ((a ^ b) < 0 && expected != 0) {
+ expected = b - expected;
+ }
+ assertEquals(expected, floorMod);
+ } catch (ArithmeticException e) {
+ if (b != 0) {
+ fail(); // Should only throw AE when b is zero.
+ }
+ }
+ }
+
+ public void testLongFloorDivMod() {
+ testFloorDivModL(123L, 456L);
+ testFloorDivModL(456L, 123L);
+ testFloorDivModL(369L, 123L);
+ testFloorDivModL(1L, 0L);
+ testFloorDivModL(Long.MAX_VALUE, 1L);
+ testFloorDivModL(Long.MAX_VALUE, -1L);
+ testFloorDivModL(Long.MIN_VALUE, 1L);
+ testFloorDivModL(Long.MIN_VALUE, -1L);
+ }
+
+ private void testFloorDivModL(long a, long b) {
+ testFloorDivL(a, b);
+ testFloorModL(a, b);
+ }
+
+ private void testFloorDivL(long a, long b) {
+ try {
+ long floorDiv = StrictMath.floorDiv(a, b);
+ long expected = a / b;
+ if (expected < 0 && a % b != 0) {
+ --expected;
+ }
+ assertEquals(expected, floorDiv);
+ } catch (ArithmeticException e) {
+ if (b != 0) {
+ fail(); // Should only throw AE when b is zero.
+ }
+ }
+ }
+
+ private void testFloorModL(long a, long b) {
+ try {
+ long floorMod = StrictMath.floorMod(a, b);
+ long expected = a % b;
+ if ((a ^ b) < 0 && expected != 0) {
+ expected = b - expected;
+ }
+ assertEquals(expected, floorMod);
+ } catch (ArithmeticException e) {
+ if (b != 0) {
+ fail(); // Should only throw AE when b is zero.
+ }
+ }
+ }
+}
diff --git a/ojluni/src/main/java/java/lang/Boolean.java b/ojluni/src/main/java/java/lang/Boolean.java
index cac469b..f71d666 100755
--- a/ojluni/src/main/java/java/lang/Boolean.java
+++ b/ojluni/src/main/java/java/lang/Boolean.java
@@ -292,4 +292,46 @@
private static boolean toBoolean(String name) {
return ((name != null) && name.equalsIgnoreCase("true"));
}
+
+ /**
+ * Returns the result of applying the logical AND operator to the
+ * specified {@code boolean} operands.
+ *
+ * @param a the first operand
+ * @param b the second operand
+ * @return the logical AND of {@code a} and {@code b}
+ * @see java.util.function.BinaryOperator
+ * @since 1.8
+ */
+ public static boolean logicalAnd(boolean a, boolean b) {
+ return a && b;
+ }
+
+ /**
+ * Returns the result of applying the logical OR operator to the
+ * specified {@code boolean} operands.
+ *
+ * @param a the first operand
+ * @param b the second operand
+ * @return the logical OR of {@code a} and {@code b}
+ * @see java.util.function.BinaryOperator
+ * @since 1.8
+ */
+ public static boolean logicalOr(boolean a, boolean b) {
+ return a || b;
+ }
+
+ /**
+ * Returns the result of applying the logical XOR operator to the
+ * specified {@code boolean} operands.
+ *
+ * @param a the first operand
+ * @param b the second operand
+ * @return the logical XOR of {@code a} and {@code b}
+ * @see java.util.function.BinaryOperator
+ * @since 1.8
+ */
+ public static boolean logicalXor(boolean a, boolean b) {
+ return a ^ b;
+ }
}
diff --git a/ojluni/src/main/java/java/lang/Math.java b/ojluni/src/main/java/java/lang/Math.java
index 0e36ab7..4c82331 100755
--- a/ojluni/src/main/java/java/lang/Math.java
+++ b/ojluni/src/main/java/java/lang/Math.java
@@ -737,6 +737,399 @@
}
/**
+ * Returns the sum of its arguments,
+ * throwing an exception if the result overflows an {@code int}.
+ *
+ * @param x the first value
+ * @param y the second value
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @since 1.8
+ */
+ public static int addExact(int x, int y) {
+ int r = x + y;
+ // HD 2-12 Overflow iff both arguments have the opposite sign of the result
+ if (((x ^ r) & (y ^ r)) < 0) {
+ throw new ArithmeticException("integer overflow");
+ }
+ return r;
+ }
+
+ /**
+ * Returns the sum of its arguments,
+ * throwing an exception if the result overflows a {@code long}.
+ *
+ * @param x the first value
+ * @param y the second value
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @since 1.8
+ */
+ public static long addExact(long x, long y) {
+ long r = x + y;
+ // HD 2-12 Overflow iff both arguments have the opposite sign of the result
+ if (((x ^ r) & (y ^ r)) < 0) {
+ throw new ArithmeticException("long overflow");
+ }
+ return r;
+ }
+
+ /**
+ * Returns the difference of the arguments,
+ * throwing an exception if the result overflows an {@code int}.
+ *
+ * @param x the first value
+ * @param y the second value to subtract from the first
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @since 1.8
+ */
+ public static int subtractExact(int x, int y) {
+ int r = x - y;
+ // HD 2-12 Overflow iff the arguments have different signs and
+ // the sign of the result is different than the sign of x
+ if (((x ^ y) & (x ^ r)) < 0) {
+ throw new ArithmeticException("integer overflow");
+ }
+ return r;
+ }
+
+ /**
+ * Returns the difference of the arguments,
+ * throwing an exception if the result overflows a {@code long}.
+ *
+ * @param x the first value
+ * @param y the second value to subtract from the first
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @since 1.8
+ */
+ public static long subtractExact(long x, long y) {
+ long r = x - y;
+ // HD 2-12 Overflow iff the arguments have different signs and
+ // the sign of the result is different than the sign of x
+ if (((x ^ y) & (x ^ r)) < 0) {
+ throw new ArithmeticException("long overflow");
+ }
+ return r;
+ }
+
+ /**
+ * Returns the product of the arguments,
+ * throwing an exception if the result overflows an {@code int}.
+ *
+ * @param x the first value
+ * @param y the second value
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @since 1.8
+ */
+ public static int multiplyExact(int x, int y) {
+ long r = (long)x * (long)y;
+ if ((int)r != r) {
+ throw new ArithmeticException("integer overflow");
+ }
+ return (int)r;
+ }
+
+ /**
+ * Returns the product of the arguments,
+ * throwing an exception if the result overflows a {@code long}.
+ *
+ * @param x the first value
+ * @param y the second value
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @since 1.8
+ */
+ public static long multiplyExact(long x, long y) {
+ long r = x * y;
+ long ax = Math.abs(x);
+ long ay = Math.abs(y);
+ if (((ax | ay) >>> 31 != 0)) {
+ // Some bits greater than 2^31 that might cause overflow
+ // Check the result using the divide operator
+ // and check for the special case of Long.MIN_VALUE * -1
+ if (((y != 0) && (r / y != x)) ||
+ (x == Long.MIN_VALUE && y == -1)) {
+ throw new ArithmeticException("long overflow");
+ }
+ }
+ return r;
+ }
+
+ /**
+ * Returns the argument incremented by one, throwing an exception if the
+ * result overflows an {@code int}.
+ *
+ * @param a the value to increment
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @since 1.8
+ */
+ public static int incrementExact(int a) {
+ if (a == Integer.MAX_VALUE) {
+ throw new ArithmeticException("integer overflow");
+ }
+
+ return a + 1;
+ }
+
+ /**
+ * Returns the argument incremented by one, throwing an exception if the
+ * result overflows a {@code long}.
+ *
+ * @param a the value to increment
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @since 1.8
+ */
+ public static long incrementExact(long a) {
+ if (a == Long.MAX_VALUE) {
+ throw new ArithmeticException("long overflow");
+ }
+
+ return a + 1L;
+ }
+
+ /**
+ * Returns the argument decremented by one, throwing an exception if the
+ * result overflows an {@code int}.
+ *
+ * @param a the value to decrement
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @since 1.8
+ */
+ public static int decrementExact(int a) {
+ if (a == Integer.MIN_VALUE) {
+ throw new ArithmeticException("integer overflow");
+ }
+
+ return a - 1;
+ }
+
+ /**
+ * Returns the argument decremented by one, throwing an exception if the
+ * result overflows a {@code long}.
+ *
+ * @param a the value to decrement
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @since 1.8
+ */
+ public static long decrementExact(long a) {
+ if (a == Long.MIN_VALUE) {
+ throw new ArithmeticException("long overflow");
+ }
+
+ return a - 1L;
+ }
+
+ /**
+ * Returns the negation of the argument, throwing an exception if the
+ * result overflows an {@code int}.
+ *
+ * @param a the value to negate
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @since 1.8
+ */
+ public static int negateExact(int a) {
+ if (a == Integer.MIN_VALUE) {
+ throw new ArithmeticException("integer overflow");
+ }
+
+ return -a;
+ }
+
+ /**
+ * Returns the negation of the argument, throwing an exception if the
+ * result overflows a {@code long}.
+ *
+ * @param a the value to negate
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @since 1.8
+ */
+ public static long negateExact(long a) {
+ if (a == Long.MIN_VALUE) {
+ throw new ArithmeticException("long overflow");
+ }
+
+ return -a;
+ }
+
+ /**
+ * Returns the value of the {@code long} argument;
+ * throwing an exception if the value overflows an {@code int}.
+ *
+ * @param value the long value
+ * @return the argument as an int
+ * @throws ArithmeticException if the {@code argument} overflows an int
+ * @since 1.8
+ */
+ public static int toIntExact(long value) {
+ if ((int)value != value) {
+ throw new ArithmeticException("integer overflow");
+ }
+ return (int)value;
+ }
+
+ /**
+ * Returns the largest (closest to positive infinity)
+ * {@code int} value that is less than or equal to the algebraic quotient.
+ * There is one special case, if the dividend is the
+ * {@linkplain Integer#MIN_VALUE Integer.MIN_VALUE} and the divisor is {@code -1},
+ * then integer overflow occurs and
+ * the result is equal to the {@code Integer.MIN_VALUE}.
+ * <p>
+ * Normal integer division operates under the round to zero rounding mode
+ * (truncation). This operation instead acts under the round toward
+ * negative infinity (floor) rounding mode.
+ * The floor rounding mode gives different results than truncation
+ * when the exact result is negative.
+ * <ul>
+ * <li>If the signs of the arguments are the same, the results of
+ * {@code floorDiv} and the {@code /} operator are the same. <br>
+ * For example, {@code floorDiv(4, 3) == 1} and {@code (4 / 3) == 1}.</li>
+ * <li>If the signs of the arguments are different, the quotient is negative and
+ * {@code floorDiv} returns the integer less than or equal to the quotient
+ * and the {@code /} operator returns the integer closest to zero.<br>
+ * For example, {@code floorDiv(-4, 3) == -2},
+ * whereas {@code (-4 / 3) == -1}.
+ * </li>
+ * </ul>
+ * <p>
+ *
+ * @param x the dividend
+ * @param y the divisor
+ * @return the largest (closest to positive infinity)
+ * {@code int} value that is less than or equal to the algebraic quotient.
+ * @throws ArithmeticException if the divisor {@code y} is zero
+ * @see #floorMod(int, int)
+ * @see #floor(double)
+ * @since 1.8
+ */
+ public static int floorDiv(int x, int y) {
+ int r = x / y;
+ // if the signs are different and modulo not zero, round down
+ if ((x ^ y) < 0 && (r * y != x)) {
+ r--;
+ }
+ return r;
+ }
+
+ /**
+ * Returns the largest (closest to positive infinity)
+ * {@code long} value that is less than or equal to the algebraic quotient.
+ * There is one special case, if the dividend is the
+ * {@linkplain Long#MIN_VALUE Long.MIN_VALUE} and the divisor is {@code -1},
+ * then integer overflow occurs and
+ * the result is equal to the {@code Long.MIN_VALUE}.
+ * <p>
+ * Normal integer division operates under the round to zero rounding mode
+ * (truncation). This operation instead acts under the round toward
+ * negative infinity (floor) rounding mode.
+ * The floor rounding mode gives different results than truncation
+ * when the exact result is negative.
+ * <p>
+ * For examples, see {@link #floorDiv(int, int)}.
+ *
+ * @param x the dividend
+ * @param y the divisor
+ * @return the largest (closest to positive infinity)
+ * {@code long} value that is less than or equal to the algebraic quotient.
+ * @throws ArithmeticException if the divisor {@code y} is zero
+ * @see #floorMod(long, long)
+ * @see #floor(double)
+ * @since 1.8
+ */
+ public static long floorDiv(long x, long y) {
+ long r = x / y;
+ // if the signs are different and modulo not zero, round down
+ if ((x ^ y) < 0 && (r * y != x)) {
+ r--;
+ }
+ return r;
+ }
+
+ /**
+ * Returns the floor modulus of the {@code int} arguments.
+ * <p>
+ * The floor modulus is {@code x - (floorDiv(x, y) * y)},
+ * has the same sign as the divisor {@code y}, and
+ * is in the range of {@code -abs(y) < r < +abs(y)}.
+ *
+ * <p>
+ * The relationship between {@code floorDiv} and {@code floorMod} is such that:
+ * <ul>
+ * <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
+ * </ul>
+ * <p>
+ * The difference in values between {@code floorMod} and
+ * the {@code %} operator is due to the difference between
+ * {@code floorDiv} that returns the integer less than or equal to the quotient
+ * and the {@code /} operator that returns the integer closest to zero.
+ * <p>
+ * Examples:
+ * <ul>
+ * <li>If the signs of the arguments are the same, the results
+ * of {@code floorMod} and the {@code %} operator are the same. <br>
+ * <ul>
+ * <li>{@code floorMod(4, 3) == 1}; and {@code (4 % 3) == 1}</li>
+ * </ul>
+ * <li>If the signs of the arguments are different, the results differ from the {@code %} operator.<br>
+ * <ul>
+ * <li>{@code floorMod(+4, -3) == -2}; and {@code (+4 % -3) == +1} </li>
+ * <li>{@code floorMod(-4, +3) == +2}; and {@code (-4 % +3) == -1} </li>
+ * <li>{@code floorMod(-4, -3) == -1}; and {@code (-4 % -3) == -1 } </li>
+ * </ul>
+ * </li>
+ * </ul>
+ * <p>
+ * If the signs of arguments are unknown and a positive modulus
+ * is needed it can be computed as {@code (floorMod(x, y) + abs(y)) % abs(y)}.
+ *
+ * @param x the dividend
+ * @param y the divisor
+ * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
+ * @throws ArithmeticException if the divisor {@code y} is zero
+ * @see #floorDiv(int, int)
+ * @since 1.8
+ */
+ public static int floorMod(int x, int y) {
+ int r = x - floorDiv(x, y) * y;
+ return r;
+ }
+
+ /**
+ * Returns the floor modulus of the {@code long} arguments.
+ * <p>
+ * The floor modulus is {@code x - (floorDiv(x, y) * y)},
+ * has the same sign as the divisor {@code y}, and
+ * is in the range of {@code -abs(y) < r < +abs(y)}.
+ *
+ * <p>
+ * The relationship between {@code floorDiv} and {@code floorMod} is such that:
+ * <ul>
+ * <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
+ * </ul>
+ * <p>
+ * For examples, see {@link #floorMod(int, int)}.
+ *
+ * @param x the dividend
+ * @param y the divisor
+ * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
+ * @throws ArithmeticException if the divisor {@code y} is zero
+ * @see #floorDiv(long, long)
+ * @since 1.8
+ */
+ public static long floorMod(long x, long y) {
+ return x - floorDiv(x, y) * y;
+ }
+
+ /**
* Returns the absolute value of an {@code int} value.
* If the argument is not negative, the argument is returned.
* If the argument is negative, the negation of the argument is returned.
@@ -1462,7 +1855,79 @@
public static float nextUp(float f) {
return sun.misc.FpUtils.nextUp(f);
}
+ /**
+ * Returns the floating-point value adjacent to {@code d} in
+ * the direction of negative infinity. This method is
+ * semantically equivalent to {@code nextAfter(d,
+ * Double.NEGATIVE_INFINITY)}; however, a
+ * {@code nextDown} implementation may run faster than its
+ * equivalent {@code nextAfter} call.
+ *
+ * <p>Special Cases:
+ * <ul>
+ * <li> If the argument is NaN, the result is NaN.
+ *
+ * <li> If the argument is negative infinity, the result is
+ * negative infinity.
+ *
+ * <li> If the argument is zero, the result is
+ * {@code -Double.MIN_VALUE}
+ *
+ * </ul>
+ *
+ * @param d starting floating-point value
+ * @return The adjacent floating-point value closer to negative
+ * infinity.
+ * @since 1.8
+ */
+ public static double nextDown(double d) {
+ if (Double.isNaN(d) || d == Double.NEGATIVE_INFINITY)
+ return d;
+ else {
+ if (d == 0.0)
+ return -Double.MIN_VALUE;
+ else
+ return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
+ ((d > 0.0d)?-1L:+1L));
+ }
+ }
+ /**
+ * Returns the floating-point value adjacent to {@code f} in
+ * the direction of negative infinity. This method is
+ * semantically equivalent to {@code nextAfter(f,
+ * Float.NEGATIVE_INFINITY)}; however, a
+ * {@code nextDown} implementation may run faster than its
+ * equivalent {@code nextAfter} call.
+ *
+ * <p>Special Cases:
+ * <ul>
+ * <li> If the argument is NaN, the result is NaN.
+ *
+ * <li> If the argument is negative infinity, the result is
+ * negative infinity.
+ *
+ * <li> If the argument is zero, the result is
+ * {@code -Float.MIN_VALUE}
+ *
+ * </ul>
+ *
+ * @param f starting floating-point value
+ * @return The adjacent floating-point value closer to negative
+ * infinity.
+ * @since 1.8
+ */
+ public static float nextDown(float f) {
+ if (Float.isNaN(f) || f == Float.NEGATIVE_INFINITY)
+ return f;
+ else {
+ if (f == 0.0f)
+ return -Float.MIN_VALUE;
+ else
+ return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
+ ((f > 0.0f)?-1:+1));
+ }
+ }
/**
* Return {@code d} ×
diff --git a/ojluni/src/main/java/java/lang/StrictMath.java b/ojluni/src/main/java/java/lang/StrictMath.java
index 23978ea..3023fc0 100755
--- a/ojluni/src/main/java/java/lang/StrictMath.java
+++ b/ojluni/src/main/java/java/lang/StrictMath.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -696,6 +696,211 @@
}
/**
+ * Returns the sum of its arguments,
+ * throwing an exception if the result overflows an {@code int}.
+ *
+ * @param x the first value
+ * @param y the second value
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @see Math#addExact(int,int)
+ * @since 1.8
+ */
+ public static int addExact(int x, int y) {
+ return Math.addExact(x, y);
+ }
+
+ /**
+ * Returns the sum of its arguments,
+ * throwing an exception if the result overflows a {@code long}.
+ *
+ * @param x the first value
+ * @param y the second value
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @see Math#addExact(long,long)
+ * @since 1.8
+ */
+ public static long addExact(long x, long y) {
+ return Math.addExact(x, y);
+ }
+
+ /**
+ * Returns the difference of the arguments,
+ * throwing an exception if the result overflows an {@code int}.
+ *
+ * @param x the first value
+ * @param y the second value to subtract from the first
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @see Math#subtractExact(int,int)
+ * @since 1.8
+ */
+ public static int subtractExact(int x, int y) {
+ return Math.subtractExact(x, y);
+ }
+
+ /**
+ * Returns the difference of the arguments,
+ * throwing an exception if the result overflows a {@code long}.
+ *
+ * @param x the first value
+ * @param y the second value to subtract from the first
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @see Math#subtractExact(long,long)
+ * @since 1.8
+ */
+ public static long subtractExact(long x, long y) {
+ return Math.subtractExact(x, y);
+ }
+
+ /**
+ * Returns the product of the arguments,
+ * throwing an exception if the result overflows an {@code int}.
+ *
+ * @param x the first value
+ * @param y the second value
+ * @return the result
+ * @throws ArithmeticException if the result overflows an int
+ * @see Math#multiplyExact(int,int)
+ * @since 1.8
+ */
+ public static int multiplyExact(int x, int y) {
+ return Math.multiplyExact(x, y);
+ }
+
+ /**
+ * Returns the product of the arguments,
+ * throwing an exception if the result overflows a {@code long}.
+ *
+ * @param x the first value
+ * @param y the second value
+ * @return the result
+ * @throws ArithmeticException if the result overflows a long
+ * @see Math#multiplyExact(long,long)
+ * @since 1.8
+ */
+ public static long multiplyExact(long x, long y) {
+ return Math.multiplyExact(x, y);
+ }
+
+ /**
+ * Returns the value of the {@code long} argument;
+ * throwing an exception if the value overflows an {@code int}.
+ *
+ * @param value the long value
+ * @return the argument as an int
+ * @throws ArithmeticException if the {@code argument} overflows an int
+ * @see Math#toIntExact(long)
+ * @since 1.8
+ */
+ public static int toIntExact(long value) {
+ return Math.toIntExact(value);
+ }
+
+ /**
+ * Returns the largest (closest to positive infinity)
+ * {@code int} value that is less than or equal to the algebraic quotient.
+ * There is one special case, if the dividend is the
+ * {@linkplain Integer#MIN_VALUE Integer.MIN_VALUE} and the divisor is {@code -1},
+ * then integer overflow occurs and
+ * the result is equal to the {@code Integer.MIN_VALUE}.
+ * <p>
+ * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
+ * a comparison to the integer division {@code /} operator.
+ *
+ * @param x the dividend
+ * @param y the divisor
+ * @return the largest (closest to positive infinity)
+ * {@code int} value that is less than or equal to the algebraic quotient.
+ * @throws ArithmeticException if the divisor {@code y} is zero
+ * @see Math#floorDiv(int, int)
+ * @see Math#floor(double)
+ * @since 1.8
+ */
+ public static int floorDiv(int x, int y) {
+ return Math.floorDiv(x, y);
+ }
+
+ /**
+ * Returns the largest (closest to positive infinity)
+ * {@code long} value that is less than or equal to the algebraic quotient.
+ * There is one special case, if the dividend is the
+ * {@linkplain Long#MIN_VALUE Long.MIN_VALUE} and the divisor is {@code -1},
+ * then integer overflow occurs and
+ * the result is equal to the {@code Long.MIN_VALUE}.
+ * <p>
+ * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
+ * a comparison to the integer division {@code /} operator.
+ *
+ * @param x the dividend
+ * @param y the divisor
+ * @return the largest (closest to positive infinity)
+ * {@code long} value that is less than or equal to the algebraic quotient.
+ * @throws ArithmeticException if the divisor {@code y} is zero
+ * @see Math#floorDiv(long, long)
+ * @see Math#floor(double)
+ * @since 1.8
+ */
+ public static long floorDiv(long x, long y) {
+ return Math.floorDiv(x, y);
+ }
+
+ /**
+ * Returns the floor modulus of the {@code int} arguments.
+ * <p>
+ * The floor modulus is {@code x - (floorDiv(x, y) * y)},
+ * has the same sign as the divisor {@code y}, and
+ * is in the range of {@code -abs(y) < r < +abs(y)}.
+ * <p>
+ * The relationship between {@code floorDiv} and {@code floorMod} is such that:
+ * <ul>
+ * <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
+ * </ul>
+ * <p>
+ * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
+ * a comparison to the {@code %} operator.
+ *
+ * @param x the dividend
+ * @param y the divisor
+ * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
+ * @throws ArithmeticException if the divisor {@code y} is zero
+ * @see Math#floorMod(int, int)
+ * @see StrictMath#floorDiv(int, int)
+ * @since 1.8
+ */
+ public static int floorMod(int x, int y) {
+ return Math.floorMod(x , y);
+ }
+ /**
+ * Returns the floor modulus of the {@code long} arguments.
+ * <p>
+ * The floor modulus is {@code x - (floorDiv(x, y) * y)},
+ * has the same sign as the divisor {@code y}, and
+ * is in the range of {@code -abs(y) < r < +abs(y)}.
+ * <p>
+ * The relationship between {@code floorDiv} and {@code floorMod} is such that:
+ * <ul>
+ * <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
+ * </ul>
+ * <p>
+ * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
+ * a comparison to the {@code %} operator.
+ *
+ * @param x the dividend
+ * @param y the divisor
+ * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
+ * @throws ArithmeticException if the divisor {@code y} is zero
+ * @see Math#floorMod(long, long)
+ * @see StrictMath#floorDiv(long, long)
+ * @since 1.8
+ */
+ public static long floorMod(long x, long y) {
+ return Math.floorMod(x, y);
+ }
+
+ /**
* Returns the absolute value of an {@code int} value..
* If the argument is not negative, the argument is returned.
* If the argument is negative, the negation of the argument is returned.
@@ -1397,6 +1602,63 @@
return sun.misc.FpUtils.nextUp(f);
}
+ /**
+ * Returns the floating-point value adjacent to {@code d} in
+ * the direction of negative infinity. This method is
+ * semantically equivalent to {@code nextAfter(d,
+ * Double.NEGATIVE_INFINITY)}; however, a
+ * {@code nextDown} implementation may run faster than its
+ * equivalent {@code nextAfter} call.
+ *
+ * <p>Special Cases:
+ * <ul>
+ * <li> If the argument is NaN, the result is NaN.
+ *
+ * <li> If the argument is negative infinity, the result is
+ * negative infinity.
+ *
+ * <li> If the argument is zero, the result is
+ * {@code -Double.MIN_VALUE}
+ *
+ * </ul>
+ *
+ * @param d starting floating-point value
+ * @return The adjacent floating-point value closer to negative
+ * infinity.
+ * @since 1.8
+ */
+ public static double nextDown(double d) {
+ return Math.nextDown(d);
+ }
+
+ /**
+ * Returns the floating-point value adjacent to {@code f} in
+ * the direction of negative infinity. This method is
+ * semantically equivalent to {@code nextAfter(f,
+ * Float.NEGATIVE_INFINITY)}; however, a
+ * {@code nextDown} implementation may run faster than its
+ * equivalent {@code nextAfter} call.
+ *
+ * <p>Special Cases:
+ * <ul>
+ * <li> If the argument is NaN, the result is NaN.
+ *
+ * <li> If the argument is negative infinity, the result is
+ * negative infinity.
+ *
+ * <li> If the argument is zero, the result is
+ * {@code -Float.MIN_VALUE}
+ *
+ * </ul>
+ *
+ * @param f starting floating-point value
+ * @return The adjacent floating-point value closer to negative
+ * infinity.
+ * @since 1.8
+ */
+ public static float nextDown(float f) {
+ return Math.nextDown(f);
+ }
/**
* Return {@code d} ×