MATH-1581: Removed "copySign" methods.
This commit is contained in:
parent
35d56cc547
commit
8157678473
|
@ -108,97 +108,6 @@ public final class MathUtils {
|
|||
return a - p * FastMath.floor((a - offset) / p) - offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
|
@ -48,34 +48,6 @@ public final class MathUtilsTest {
|
|||
Assert.assertFalse(MathUtils.equals(mZero, zero));
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@ -143,34 +115,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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue