Search in sources :

Example 21 with Context

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

the class BigFloatTest method testContext.

@Test
public void testContext() {
    MathContext mathContext = new MathContext(20);
    Context context = context(mathContext);
    assertEquals(mathContext, context.getMathContext());
    assertEquals(mathContext.getPrecision(), context.getPrecision());
    assertEquals(mathContext.getRoundingMode(), context.getRoundingMode());
    assertEquals(1000, context(1000).getPrecision());
    assertEquals(context, context(mathContext));
    assertEquals(context.hashCode(), context(mathContext).hashCode());
    assertEquals(context.toString(), context(mathContext).toString());
    assertNotEquals(context, null);
    assertNotEquals(context, "string");
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) MathContext(java.math.MathContext) Test(org.junit.Test)

Example 22 with Context

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

the class BigFloatTest method testIsEqual.

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

Example 23 with Context

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

the class BigFloatTest method testLog10.

@Test
public void testLog10() {
    Context context = context(MathContext.DECIMAL32);
    assertEquals(log10(context.valueOf(3)).toBigDecimal(), BigDecimalMath.log10(BigDecimal.valueOf(3), MathContext.DECIMAL32));
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 24 with Context

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

the class BigFloatTest method testAsin.

@Test
public void testAsin() {
    Context context = context(MathContext.DECIMAL32);
    assertEquals(asin(context.valueOf(0)).toBigDecimal(), BigDecimalMath.asin(BigDecimal.valueOf(0), MathContext.DECIMAL32));
}
Also used : MathContext(java.math.MathContext) Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 25 with Context

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

the class BigFloatStreamTest method testRangeClosedStep3.

@Test
public void testRangeClosedStep3() {
    Context context = BigFloat.context(20);
    List<BigFloat> list = BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(12), context.valueOf(3)).collect(Collectors.toList());
    assertEquals(5, list.size());
    assertEquals(true, list.contains(context.valueOf(0)));
    assertEquals(true, list.contains(context.valueOf(3)));
    assertEquals(true, list.contains(context.valueOf(6)));
    assertEquals(true, list.contains(context.valueOf(9)));
    assertEquals(true, list.contains(context.valueOf(12)));
    assertEquals(0, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(-1), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(1, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(0), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(1, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(1), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(1, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(2), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(2, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(3), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(2, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(4), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(2, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(5), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(3, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(6), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(3, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(7), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(3, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(8), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(4, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(9), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(4, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(10), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(4, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(11), context.valueOf(3)).collect(Collectors.toList()).size());
    assertEquals(5, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(12), context.valueOf(3)).collect(Collectors.toList()).size());
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) 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