Search in sources :

Example 36 with Context

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()));
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) MathContext(java.math.MathContext) Test(org.junit.Test)

Example 37 with Context

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());
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 38 with Context

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)));
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 39 with Context

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());
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 40 with Context

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)));
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Aggregations

Context (ch.obermuhlner.math.big.BigFloat.Context)78 Test (org.junit.Test)76 MathContext (java.math.MathContext)61 BigFloat (ch.obermuhlner.math.big.BigFloat)15