Skip to content

mpobjects/bdparsii

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central Javadocs Vulnerability Scan Build Status Coverage Status Quality Gate Status Sonatype Nexus (Snapshots)

bdparsii

A BigDecimal port of Scireum's Parsii library.

Using it is as simple as:

Scope scope = Scope.create();   
Variable a = scope.getVariable("a");   
Expression expr = Parser.parse("3 + a * 4", scope);   
a.setValue(4);   
System.out.println(expr.evaluate());   
a.setValue(5);   
System.out.println(expr.evaluate());

MathContext

An important part of calculations with BigDecimals is the MathContext. By default DECIMAL64 is used, which is similar to the double precision.

The MathContext can be set on the Scope instance. It can also be passed on in the evaluate method of expression. But this will not affect parts of the expression which were simplified to constants.

Complex mathematical functions are executed by the Big Math library. Most of these functions do not support unlimited precision (as there simply is no end). In this case a fallback MathContext is used, which is by default DECIMAL128.

Performance

Due to calculation on arbitrary-precision decimals the performance of calculations is significantly worse than the calculations performed by the double based parsii. Performance depends a lot on the used precision and used mathematical functions.

For more information see the performance test suite.

Download

bdparsii is available from the maven central repository:

<dependency>
	<groupId>com.mpobjects</groupId>
	<artifactId>bdparsii</artifactId>
	<version>1.0.0</version>
</dependency>