Search in sources :

Example 11 with BigFloat

use of ch.obermuhlner.math.big.BigFloat 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 12 with BigFloat

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

the class BigFloatStreamTest method testRangeStep1.

@Test
public void testRangeStep1() {
    Context context = BigFloat.context(20);
    List<BigFloat> list = BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(1)).collect(Collectors.toList());
    assertList(list, 0, 10);
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) Test(org.junit.Test)

Example 13 with BigFloat

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

the class BigFloatStreamTest method testRangeParallel.

@Test
public void testRangeParallel() {
    Context context = BigFloat.context(20);
    List<BigFloat> list = BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(1)).parallel().collect(Collectors.toList());
    assertList(list, 0, 10);
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) Test(org.junit.Test)

Example 14 with BigFloat

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

the class BigFloatStreamTest method testRangeClosedStep1.

@Test
public void testRangeClosedStep1() {
    Context context = BigFloat.context(20);
    List<BigFloat> list = BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(10), context.valueOf(1)).collect(Collectors.toList());
    assertListClosed(list, 0, 10);
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) Test(org.junit.Test)

Example 15 with BigFloat

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

the class BigFloatStreamTest method testRangeClosedLongStep3.

@Test
public void testRangeClosedLongStep3() {
    Context context = BigFloat.context(20);
    List<BigFloat> list = BigFloatStream.rangeClosed(0, 12, 3, context).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)));
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) Test(org.junit.Test)

Aggregations

BigFloat (ch.obermuhlner.math.big.BigFloat)15 Context (ch.obermuhlner.math.big.BigFloat.Context)15 Test (org.junit.Test)14 MathContext (java.math.MathContext)1