use of java.math.MathContext in project robovm by robovm.
the class BigDecimalArithmeticTest method testRemainderMathContextHALF_DOWN.
/**
* remainder(BigDecimal, MathContext)
*/
public void testRemainderMathContextHALF_DOWN() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = -45;
String b = "134432345432345748766876876723342238476237823787879183470";
int bScale = 10;
int precision = 75;
RoundingMode rm = RoundingMode.HALF_DOWN;
MathContext mc = new MathContext(precision, rm);
String res = "1149310942946292909508821656680979993738625937.2065885780";
int resScale = 10;
BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
BigDecimal result = aNumber.remainder(bNumber, mc);
assertEquals("incorrect quotient value", res, result.toString());
assertEquals("incorrect quotient scale", resScale, result.scale());
}
use of java.math.MathContext in project robovm by robovm.
the class BigDecimalArithmeticTest method testSubtractMathContextDiffScaleNegPos.
/**
* Subtract two numbers of different scales using MathContext;
* the first is negative
*/
public void testSubtractMathContextDiffScaleNegPos() {
String a = "986798656676789766678767876078779810457634781384756794987";
int aScale = -15;
String b = "747233429293018787918347987234564568";
int bScale = 40;
String c = "9.867986566767897666787678760787798104576347813847567949870000000000000E+71";
int cScale = -2;
BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
MathContext mc = new MathContext(70, RoundingMode.HALF_DOWN);
BigDecimal result = aNumber.subtract(bNumber, mc);
assertEquals("incorrect value", c, result.toString());
assertEquals("incorrect scale", cScale, result.scale());
}
use of java.math.MathContext in project robovm by robovm.
the class BigDecimalArithmeticTest method testMultiplyMathContextScalePosPos.
/**
* Multiply two numbers of positive scales using MathContext
*/
public void testMultiplyMathContextScalePosPos() {
String a = "97665696756578755423325476545428779810457634781384756794987";
int aScale = -25;
String b = "87656965586786097685674786576598865";
int bScale = 10;
String c = "8.561078619600910561431314228543672720908E+108";
int cScale = -69;
BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
MathContext mc = new MathContext(40, RoundingMode.HALF_DOWN);
BigDecimal result = aNumber.multiply(bNumber, mc);
assertEquals("incorrect value", c, result.toString());
assertEquals("incorrect scale", cScale, result.scale());
}
use of java.math.MathContext in project robovm by robovm.
the class BigDecimalArithmeticTest method testAddMathContextEqualScaleNegNeg.
/**
* Add two numbers of equal negative scales using MathContext
*/
public void testAddMathContextEqualScaleNegNeg() {
String a = "1231212478987482988429808779810457634781384756794987";
int aScale = -10;
String b = "747233429293018787918347987234564568";
int bScale = -10;
String c = "1.2312E+61";
int cScale = -57;
BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
MathContext mc = new MathContext(5, RoundingMode.FLOOR);
BigDecimal result = aNumber.add(bNumber, mc);
assertEquals("incorrect value ", c, result.toString());
assertEquals("incorrect scale", cScale, result.scale());
}
use of java.math.MathContext in project robovm by robovm.
the class BigDecimalArithmeticTest method testRoundMathContextPrecision0.
/**
* round(BigDecimal, MathContext) when precision = 0
*/
public void testRoundMathContextPrecision0() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 45;
int precision = 0;
RoundingMode rm = RoundingMode.HALF_UP;
MathContext mc = new MathContext(precision, rm);
String res = "3736186567876.876578956958765675671119238118911893939591735";
BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
BigDecimal result = aNumber.round(mc);
assertEquals("incorrect quotient value", res, result.toString());
assertEquals("incorrect quotient scale", aScale, result.scale());
}
Aggregations