use of java.math.BigDecimal in project guava by google.
the class LongMathTest method testDivNonZero.
// TODO
@GwtIncompatible
// TODO(cpovirk): File BigDecimal.divide() rounding bug.
@AndroidIncompatible
public void testDivNonZero() {
for (long p : NONZERO_LONG_CANDIDATES) {
for (long q : NONZERO_LONG_CANDIDATES) {
for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) {
long expected = new BigDecimal(valueOf(p)).divide(new BigDecimal(valueOf(q)), 0, mode).longValue();
long actual = LongMath.divide(p, q, mode);
if (expected != actual) {
failFormat("expected divide(%s, %s, %s) = %s; got %s", p, q, mode, expected, actual);
}
}
}
}
}
use of java.math.BigDecimal in project guava by google.
the class DoubleMathTest method testRoundIntegralDoubleToBigInteger.
// DoubleMath.roundToBigInteger(double, RoundingMode)
@GwtIncompatible
public void testRoundIntegralDoubleToBigInteger() {
for (double d : INTEGRAL_DOUBLE_CANDIDATES) {
for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) {
BigDecimal expected = new BigDecimal(d).setScale(0, mode);
assertEquals(expected.toBigInteger(), DoubleMath.roundToBigInteger(d, mode));
}
}
}
use of java.math.BigDecimal in project j2objc by google.
the class BigDecimalTest method test_abs.
/**
* @tests java.math.BigDecimal#abs()
*/
public void test_abs() {
BigDecimal big = new BigDecimal("-1234");
BigDecimal bigabs = big.abs();
assertTrue("the absolute value of -1234 is not 1234", bigabs.toString().equals("1234"));
big = new BigDecimal(new BigInteger("2345"), 2);
bigabs = big.abs();
assertTrue("the absolute value of 23.45 is not 23.45", bigabs.toString().equals("23.45"));
}
use of java.math.BigDecimal in project j2objc by google.
the class BigDecimalTest method test_subtractLjava_math_BigDecimal.
/**
* @tests java.math.BigDecimal#subtract(java.math.BigDecimal)
*/
public void test_subtractLjava_math_BigDecimal() {
BigDecimal sub1 = new BigDecimal("13948");
BigDecimal sub2 = new BigDecimal("2839.489");
BigDecimal result = sub1.subtract(sub2);
assertTrue("13948 - 2839.489 is wrong: " + result, result.toString().equals("11108.511") && result.scale() == 3);
BigDecimal result2 = sub2.subtract(sub1);
assertTrue("2839.489 - 13948 is wrong", result2.toString().equals("-11108.511") && result2.scale() == 3);
assertTrue("13948 - 2839.489 is not the negative of 2839.489 - 13948", result.equals(result2.negate()));
sub1 = new BigDecimal(value, 1);
sub2 = new BigDecimal("0");
result = sub1.subtract(sub2);
assertTrue("1234590.8 - 0 is wrong", result.equals(sub1));
sub1 = new BigDecimal(1.234E-03);
sub2 = new BigDecimal(3.423E-10);
result = sub1.subtract(sub2);
assertTrue("1.234E-03 - 3.423E-10 is wrong, " + result.doubleValue(), result.doubleValue() == 0.0012339996577);
sub1 = new BigDecimal(1234.0123);
sub2 = new BigDecimal(1234.0123000);
result = sub1.subtract(sub2);
assertTrue("1234.0123 - 1234.0123000 is wrong, " + result.doubleValue(), result.doubleValue() == 0.0);
}
use of java.math.BigDecimal in project j2objc by google.
the class BigDecimalTest method test_negate.
/**
* @tests java.math.BigDecimal#negate()
*/
public void test_negate() {
BigDecimal negate1 = new BigDecimal(value2, 7);
assertTrue("the negate of 1233.4560000 is not -1233.4560000", negate1.negate().toString().equals("-1233.4560000"));
negate1 = new BigDecimal("-23465839");
assertTrue("the negate of -23465839 is not 23465839", negate1.negate().toString().equals("23465839"));
negate1 = new BigDecimal(-3.456E6);
assertTrue("the negate of -3.456E6 is not 3.456E6", negate1.negate().negate().equals(negate1));
}
Aggregations