MathUtils { public static byte copySign(byte magnitude, byte sign) throws MathArithmeticException { if ((magnitude >= 0 && sign >= 0) || (magnitude < 0 && sign < 0)) { return magnitude; } else if (sign >= 0 && magnitude == Byte.MIN_VALUE) { throw new MathArithmeticException(LocalizedFormats.OVERFLOW); } else { return (byte) -magnitude; } } private  MathUtils(); static int hash(double value); static boolean equals(double x, double y); static int hash(double[] value); static double normalizeAngle(double a, double center); static double reduce(double a,
                                double period,
                                double offset); static byte copySign(byte magnitude, byte sign); static short copySign(short magnitude, short sign); static int copySign(int magnitude, int sign); static long copySign(long magnitude, long sign); static void checkFinite(final double x); static void checkFinite(final double[] val); static void checkNotNull(Object o,
                                    Localizable pattern,
                                    Object ... args); static void checkNotNull(Object o); static final double TWO_PI; static final double PI_SQUARED; }
@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 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 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); }