You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/05/25 22:29:33 UTC
[commons-math] 02/04: MATH-1581: Removed "copySign" methods.
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch modularized_master
in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit 8157678473cddeb3fee465136d3b66414293259b
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Tue May 25 23:44:45 2021 +0200
MATH-1581: Removed "copySign" methods.
---
.../commons/math4/legacy/util/MathUtils.java | 91 ---------------------
.../commons/math4/legacy/util/MathUtilsTest.java | 92 ----------------------
2 files changed, 183 deletions(-)
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathUtils.java
index 5336875..c78a753 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathUtils.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/util/MathUtils.java
@@ -109,97 +109,6 @@ public final class MathUtils {
}
/**
- * Returns the first argument with the sign of the second argument.
- *
- * @param magnitude Magnitude of the returned value.
- * @param sign Sign of the returned value.
- * @return a value with magnitude equal to {@code magnitude} and with the
- * same sign as the {@code sign} argument.
- * @throws MathArithmeticException if {@code magnitude == Byte.MIN_VALUE}
- * and {@code sign >= 0}.
- */
- public static byte copySign(byte magnitude, byte sign)
- throws MathArithmeticException {
- if ((magnitude >= 0 && sign >= 0) ||
- (magnitude < 0 && sign < 0)) { // Sign is OK.
- return magnitude;
- } else if (sign >= 0 &&
- magnitude == Byte.MIN_VALUE) {
- throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
- } else {
- return (byte) -magnitude; // Flip sign.
- }
- }
-
- /**
- * Returns the first argument with the sign of the second argument.
- *
- * @param magnitude Magnitude of the returned value.
- * @param sign Sign of the returned value.
- * @return a value with magnitude equal to {@code magnitude} and with the
- * same sign as the {@code sign} argument.
- * @throws MathArithmeticException if {@code magnitude == Short.MIN_VALUE}
- * and {@code sign >= 0}.
- */
- public static short copySign(short magnitude, short sign)
- throws MathArithmeticException {
- if ((magnitude >= 0 && sign >= 0) ||
- (magnitude < 0 && sign < 0)) { // Sign is OK.
- return magnitude;
- } else if (sign >= 0 &&
- magnitude == Short.MIN_VALUE) {
- throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
- } else {
- return (short) -magnitude; // Flip sign.
- }
- }
-
- /**
- * Returns the first argument with the sign of the second argument.
- *
- * @param magnitude Magnitude of the returned value.
- * @param sign Sign of the returned value.
- * @return a value with magnitude equal to {@code magnitude} and with the
- * same sign as the {@code sign} argument.
- * @throws MathArithmeticException if {@code magnitude == Integer.MIN_VALUE}
- * and {@code sign >= 0}.
- */
- public static int copySign(int magnitude, int sign)
- throws MathArithmeticException {
- if ((magnitude >= 0 && sign >= 0) ||
- (magnitude < 0 && sign < 0)) { // Sign is OK.
- return magnitude;
- } else if (sign >= 0 &&
- magnitude == Integer.MIN_VALUE) {
- throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
- } else {
- return -magnitude; // Flip sign.
- }
- }
-
- /**
- * Returns the first argument with the sign of the second argument.
- *
- * @param magnitude Magnitude of the returned value.
- * @param sign Sign of the returned value.
- * @return a value with magnitude equal to {@code magnitude} and with the
- * same sign as the {@code sign} argument.
- * @throws MathArithmeticException if {@code magnitude == Long.MIN_VALUE}
- * and {@code sign >= 0}.
- */
- public static long copySign(long magnitude, long sign)
- throws MathArithmeticException {
- if ((magnitude >= 0 && sign >= 0) ||
- (magnitude < 0 && sign < 0)) { // Sign is OK.
- return magnitude;
- } else if (sign >= 0 &&
- magnitude == Long.MIN_VALUE) {
- throw new MathArithmeticException(LocalizedFormats.OVERFLOW);
- } else {
- return -magnitude; // Flip sign.
- }
- }
- /**
* Check that the argument is a real number.
*
* @param x Argument.
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathUtilsTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathUtilsTest.java
index 5023783..1399411 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathUtilsTest.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/util/MathUtilsTest.java
@@ -49,34 +49,6 @@ public final class MathUtilsTest {
}
@Test
- public void testIndicatorByte() {
- Assert.assertEquals((byte)1, MathUtils.copySign((byte)1, (byte)2));
- Assert.assertEquals((byte)1, MathUtils.copySign((byte)1, (byte)0));
- Assert.assertEquals((byte)(-1), MathUtils.copySign((byte)1, (byte)(-2)));
- }
-
- @Test
- public void testIndicatorInt() {
- Assert.assertEquals(1, MathUtils.copySign(1, 2));
- Assert.assertEquals(1, MathUtils.copySign(1, 0));
- Assert.assertEquals((-1), MathUtils.copySign(1, -2));
- }
-
- @Test
- public void testIndicatorLong() {
- Assert.assertEquals(1L, MathUtils.copySign(1L, 2L));
- Assert.assertEquals(1L, MathUtils.copySign(1L, 0L));
- Assert.assertEquals(-1L, MathUtils.copySign(1L, -2L));
- }
-
- @Test
- public void testIndicatorShort() {
- Assert.assertEquals((short)1, MathUtils.copySign((short)1, (short)2));
- Assert.assertEquals((short)1, MathUtils.copySign((short)1, (short)0));
- Assert.assertEquals((short)(-1), MathUtils.copySign((short)1, (short)(-2)));
- }
-
- @Test
public void testReduce() {
final double period = -12.222;
final double offset = 13;
@@ -144,34 +116,6 @@ public final class MathUtilsTest {
}
@Test
- public void testSignByte() {
- final byte one = (byte) 1;
- Assert.assertEquals((byte) 1, MathUtils.copySign(one, (byte) 2));
- Assert.assertEquals((byte) (-1), MathUtils.copySign(one, (byte) (-2)));
- }
-
- @Test
- public void testSignInt() {
- final int one = 1;
- Assert.assertEquals(1, MathUtils.copySign(one, 2));
- Assert.assertEquals((-1), MathUtils.copySign(one, -2));
- }
-
- @Test
- public void testSignLong() {
- final long one = 1L;
- Assert.assertEquals(1L, MathUtils.copySign(one, 2L));
- Assert.assertEquals(-1L, MathUtils.copySign(one, -2L));
- }
-
- @Test
- public void testSignShort() {
- final short one = (short) 1;
- Assert.assertEquals((short) 1, MathUtils.copySign(one, (short) 2));
- Assert.assertEquals((short) (-1), MathUtils.copySign(one, (short) (-2)));
- }
-
- @Test
public void testCheckFinite() {
try {
MathUtils.checkFinite(Double.POSITIVE_INFINITY);
@@ -231,40 +175,4 @@ public final class MathUtilsTest {
// Expected.
}
}
-
- @Test
- public void testCopySignByte() {
- byte a = MathUtils.copySign(Byte.MIN_VALUE, (byte) -1);
- Assert.assertEquals(Byte.MIN_VALUE, a);
-
- final byte minValuePlusOne = Byte.MIN_VALUE + (byte) 1;
- a = MathUtils.copySign(minValuePlusOne, (byte) 1);
- Assert.assertEquals(Byte.MAX_VALUE, a);
-
- a = MathUtils.copySign(Byte.MAX_VALUE, (byte) -1);
- Assert.assertEquals(minValuePlusOne, a);
-
- final byte one = 1;
- byte val = -2;
- a = MathUtils.copySign(val, one);
- Assert.assertEquals(-val, a);
-
- final byte minusOne = -one;
- val = 2;
- a = MathUtils.copySign(val, minusOne);
- Assert.assertEquals(-val, a);
-
- val = 0;
- a = MathUtils.copySign(val, minusOne);
- Assert.assertEquals(val, a);
-
- val = 0;
- a = MathUtils.copySign(val, one);
- Assert.assertEquals(val, a);
- }
-
- @Test(expected=MathArithmeticException.class)
- public void testCopySignByte2() {
- MathUtils.copySign(Byte.MIN_VALUE, (byte) 1);
- }
}