use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testMultiply.
@Test
public void testMultiply() {
Context context = context(MathContext.DECIMAL32);
assertEquals(context.valueOf(6), context.valueOf(2).multiply(3));
assertEquals(context.valueOf(6), context.valueOf(2).multiply(3L));
assertEquals(context.valueOf(6), context.valueOf(2).multiply(3.0));
assertEquals(context.valueOf(6), context.valueOf(2).multiply(BigDecimal.valueOf(3)));
assertEquals(context.valueOf(6), context.valueOf(2).multiply(context.valueOf(3)));
}
use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testAddBigFloat.
@Test
public void testAddBigFloat() {
Context smallContext = context(MathContext.DECIMAL32);
Context largeContext = context(MathContext.DECIMAL64);
assertEquals(smallContext, smallContext.valueOf(2).add(smallContext.valueOf(3)).getContext());
assertEquals(largeContext, smallContext.valueOf(2).add(largeContext.valueOf(3)).getContext());
assertEquals(largeContext, largeContext.valueOf(2).add(smallContext.valueOf(3)).getContext());
assertEquals(largeContext, largeContext.valueOf(2).add(largeContext.valueOf(3)).getContext());
}
use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testDivide.
@Test
public void testDivide() {
Context context = context(MathContext.DECIMAL32);
assertEquals(context.valueOf(2), context.valueOf(6).divide(3));
assertEquals(context.valueOf(2), context.valueOf(6).divide(3L));
assertEquals(context.valueOf(2), context.valueOf(6).divide(3.0));
assertEquals(context.valueOf(2), context.valueOf(6).divide(BigDecimal.valueOf(3)));
assertEquals(context.valueOf(2), context.valueOf(6).divide(context.valueOf(3)));
}
use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testHashCode.
@Test
public void testHashCode() {
Context context = context(MathContext.DECIMAL32);
assertEquals(context.valueOf(1).hashCode(), context.valueOf(1).hashCode());
assertNotEquals(context.valueOf(1).hashCode(), context.valueOf(999).hashCode());
Context equalContext = context(MathContext.DECIMAL32);
assertEquals(context, equalContext);
assertEquals(context.valueOf(1).hashCode(), equalContext.valueOf(1).hashCode());
assertEquals(context.valueOf(1).hashCode(), equalContext.valueOf(1.0).hashCode());
assertEquals(context.valueOf(1).hashCode(), equalContext.valueOf("1.0000").hashCode());
assertNotEquals(context.valueOf(1).hashCode(), equalContext.valueOf(999).hashCode());
Context anotherContext = context(MathContext.DECIMAL64);
assertEquals(context.valueOf(1).hashCode(), anotherContext.valueOf(1).hashCode());
}
use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testGetExponent.
@Test
public void testGetExponent() {
Context context = context(MathContext.DECIMAL32);
assertEquals(context.valueOf(99), context.valueOf(1.23E99).getExponent());
}
Aggregations