Search in sources :

Example 66 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatTest method testIsZero.

@Test
public void testIsZero() {
    Context context = context(MathContext.DECIMAL32);
    assertEquals(false, context.valueOf("-1E999").isZero());
    assertEquals(false, context.valueOf("-1E-999").isZero());
    assertEquals(false, context.valueOf(-5).isZero());
    assertEquals(true, context.valueOf(0).isZero());
    assertEquals(true, context.valueOf("0.000000").isZero());
    assertEquals(false, context.valueOf(5).isZero());
    assertEquals(false, context.valueOf("1E999").isZero());
    assertEquals(false, context.valueOf("1E-999").isZero());
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 67 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatTest method testIsGreaterThan.

@Test
public void testIsGreaterThan() {
    Context context = context(MathContext.DECIMAL32);
    assertEquals(true, context.valueOf(5).isGreaterThan(context.valueOf(1)));
    assertEquals(false, context.valueOf(1).isGreaterThan(context.valueOf(5)));
    assertEquals(false, context.valueOf(5).isGreaterThan(context.valueOf(5)));
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 68 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatTest method testPi.

@Test
public void testPi() {
    Context context = context(MathContext.DECIMAL32);
    assertEquals(BigDecimalMath.pi(context.getMathContext()), context.pi().toBigDecimal());
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 69 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatTest method testEquals.

@Test
public void testEquals() {
    Context context = context(MathContext.DECIMAL32);
    assertNotEquals(context.valueOf(1234), null);
    assertNotEquals(context.valueOf(1234), "string");
    BigFloat value1 = context.valueOf(1);
    assertEquals(value1, value1);
    assertEquals(context.valueOf(1234), context.valueOf(1234));
    assertNotEquals(context.valueOf(1234), context.valueOf(9999));
    assertNotEquals(context.valueOf(9999), context.valueOf(1234));
    Context equalContext = context(MathContext.DECIMAL32);
    assertEquals(context, equalContext);
    assertEquals(context.valueOf(1234), equalContext.valueOf(1234));
    assertEquals(context.valueOf(1234), equalContext.valueOf(1234.0));
    assertEquals(context.valueOf(1234), equalContext.valueOf("1234.0000"));
    assertEquals(equalContext.valueOf(1234), context.valueOf(1234));
    Context anotherContext = context(MathContext.DECIMAL64);
    assertNotEquals(context, anotherContext);
    assertEquals(context.valueOf(1234), anotherContext.valueOf(1234));
    assertEquals(anotherContext.valueOf(1234), context.valueOf(1234));
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) Test(org.junit.Test)

Example 70 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatTest method testSignum.

@Test
public void testSignum() {
    Context context = context(MathContext.DECIMAL32);
    assertEquals(-1, context.valueOf("-1E999").signum());
    assertEquals(-1, context.valueOf("-1E-999").signum());
    assertEquals(-1, context.valueOf(-5).signum());
    assertEquals(0, context.valueOf(0).signum());
    assertEquals(0, context.valueOf("0.000000").signum());
    assertEquals(1, context.valueOf(5).signum());
    assertEquals(1, context.valueOf("1E999").signum());
    assertEquals(1, context.valueOf("1E-999").signum());
}
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