Search in sources :

Example 51 with Context

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

Example 52 with Context

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

Example 53 with Context

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

Example 54 with Context

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

Example 55 with Context

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());
}
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