https://github.com/facaiy/math-expression-parser
A scala library for parsing mathemitical expressions with support for parentheses and variables.
https://github.com/facaiy/math-expression-parser
math-expression-parser parsing-mathemitical-expressions scala-library
Last synced: 9 months ago
JSON representation
A scala library for parsing mathemitical expressions with support for parentheses and variables.
- Host: GitHub
- URL: https://github.com/facaiy/math-expression-parser
- Owner: facaiy
- License: mit
- Created: 2017-06-21T10:01:42.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-04-23T07:03:38.000Z (almost 6 years ago)
- Last Synced: 2025-05-16T00:42:01.169Z (11 months ago)
- Topics: math-expression-parser, parsing-mathemitical-expressions, scala-library
- Language: Scala
- Size: 52.7 KB
- Stars: 12
- Watchers: 1
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# math-expression-parser
[
](https://travis-ci.org/facaiy/math-expression-parser)
[
](http://search.maven.org/#search|ga|1|g:"io.github.facaiy"%20AND%20a:"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`](http://www.scala-lang.org/api/2.12.1/scala/math/index.html), except of `random`, `E` and `PI`
+ variable name: `$` with valid Java variable name
### Install
1. maven
```
io.github.facaiy
math-expression-parser
0.0.2
```
### Usage
A simple example:
```scala
import io.github.facaiy.math.expression.MathExp
val str = "1.0 + sqrt(2 * $a1) + $a2 ** 2"
val ex = MathExp.parse(str)
val variables = Map("a1" -> 2, "a2" -> 1)
val output = ex.eval(variables)
// output = 4.0
val output1 = ex.eval(Map("a1" -> 8.0, "a2" -> 2))
// output1 = 9.0
```
### Release
```bash
# Ref: https://central.sonatype.org/pages/apache-maven.html
mvn release:clean release:prepare
mvn release:perform
```