Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Parses, compiles and evaluates mathematical expressions

License

Notifications You must be signed in to change notification settings

gkozlenko/math-expression-evaluator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

math-expression-evaluator

build status test coverage license

Parses, compiles and evaluates mathematical expressions

Examples

// Import class
import com.gkozlenko.math.Expression;

// Compile the expression
Expression expression = Expression.parse("(10 - :x) * (5 + :y)");

// Set parameters
expression.setParameter(":x", 2).setParameter(":y", 3);

// Calculate
System.out.println(expression.calculate()); // Outputs 64

// Set other parameters
expression.setParameter(":x", 4.5).setParameter(":y", -1.5);

// Calculate again
System.out.println(expression.calculate()); // Outputs 19.25

Supported symbols

Symbol Explanation Example
+ Addition operator 1 + 2 results 3
- Subtraction operator 10 - 3 results 7
* Multiplication operator 5 * 2 results 10
/ Division operator 6 / 3 results 2
( Opening parenthesis (5 - 2) * 2 results 6
) Closing parenthesis (5 - 2) * 2 results 6
: Parameter prefix :name

About

Parses, compiles and evaluates mathematical expressions

Topics

Resources

License

Stars

Watchers

Forks

Languages