Skip to content

Repository files navigation

math-expression-parser

A scala library for parsing mathemitical expressions with support for parentheses and variables.

features:

  • math operators: +, -, *, /, **(power)
  • parentheses ( ) and comma ,
  • all function of scala.math, except of random, E and PI
  • variable name: $ with valid Java variable name

Install

  1. maven
    <dependency>
    <groupId>io.github.facaiy</groupId>
    <artifactId>math-expression-parser</artifactId>
    <version>0.0.2</version>
    </dependency>
    

Usage

A simple example:

importio.github.facaiy.math.expression.MathExpvalstr="1.0 + sqrt(2 * $a1) + $a2 ** 2"valex=MathExp.parse(str)
valvariables=Map("a1"->2, "a2"->1)
valoutput= ex.eval(variables)
// output = 4.0valoutput1= ex.eval(Map("a1"->8.0, "a2"->2))
// output1 = 9.0

Release

# Ref: https://central.sonatype.org/pages/apache-maven.html
mvn release:clean release:prepare
mvn release:perform

About

A scala library for parsing mathemitical expressions with support for parentheses and variables.

Topics

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages