use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testValueOfRounding.
@Test
public void testValueOfRounding() {
Context context = context(new MathContext(3));
assertEquals(0, BigDecimal.valueOf(123000).compareTo(context.valueOf(123456).toBigDecimal()));
assertEquals(0, BigDecimal.valueOf(123000).compareTo(context.valueOf(123456L).toBigDecimal()));
assertEquals(0, BigDecimal.valueOf(123000).compareTo(context.valueOf(123456.0).toBigDecimal()));
assertEquals(0, BigDecimal.valueOf(123000).compareTo(context.valueOf(BigDecimal.valueOf(123456)).toBigDecimal()));
assertEquals(0, BigDecimal.valueOf(123000).compareTo(context.valueOf(context(20).valueOf(123456)).toBigDecimal()));
}
use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testGetMantissa.
@Test
public void testGetMantissa() {
Context context = context(MathContext.DECIMAL32);
assertEquals(context.valueOf(1.23), context.valueOf(1.23E99).getMantissa());
}
use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testRemainder.
@Test
public void testRemainder() {
Context context = context(MathContext.DECIMAL32);
assertEquals(context.valueOf(1), context.valueOf(10).remainder(3));
assertEquals(context.valueOf(1), context.valueOf(10).remainder(3L));
assertEquals(context.valueOf(1), context.valueOf(10).remainder(3.0));
assertEquals(context.valueOf(1), context.valueOf(10).remainder(BigDecimal.valueOf(3)));
assertEquals(context.valueOf(1), context.valueOf(10).remainder(context.valueOf(3)));
}
use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testValueOf.
@Test
public void testValueOf() {
Context context = context(MathContext.DECIMAL32);
assertEquals(0, BigDecimal.ONE.compareTo(context.valueOf(BigDecimal.ONE).toBigDecimal()));
assertEquals(0, BigDecimal.ONE.compareTo(context.valueOf(1).toBigDecimal()));
assertEquals(0, BigDecimal.ONE.compareTo(context.valueOf(1L).toBigDecimal()));
assertEquals(0, BigDecimal.ONE.compareTo(context.valueOf(1.0).toBigDecimal()));
Context anotherContext = context(MathContext.DECIMAL64);
assertEquals(0, BigDecimal.ONE.compareTo(context.valueOf(anotherContext.valueOf(1.0)).toBigDecimal()));
assertEquals(0, BigDecimal.ONE.compareTo(anotherContext.valueOf(context.valueOf(1.0)).toBigDecimal()));
assertEquals(context, context.valueOf(anotherContext.valueOf(1.0)).getContext());
assertEquals(anotherContext, anotherContext.valueOf(context.valueOf(1.0)).getContext());
}
use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.
the class BigFloatTest method testRoot.
@Test
public void testRoot() {
Context context = context(MathContext.DECIMAL32);
assertEquals(context.valueOf(2), context.valueOf(8).root(3));
assertEquals(context.valueOf(2), context.valueOf(8).root(3L));
assertEquals(context.valueOf(2), context.valueOf(8).root(3.0));
assertEquals(context.valueOf(2), context.valueOf(8).root(BigDecimal.valueOf(3)));
assertEquals(context.valueOf(2), context.valueOf(8).root(context.valueOf(3)));
}
Aggregations