lieval
lieval is a lightweight Rust crate for parsing and evaluating mathematical expressions from strings.
Features
- Parse and evaluate simple mathematical expressions.
- Basic arithmetic operations:
+,-,*,/,% - Parentheses for expression grouping
- Common mathematical functions:
sin,cos,atan,cosh,pow,sqrt,hypot,exp,ln,div_euclid,flooretc...
- Basic arithmetic operations:
- Support for variables, operators, and functions.
- Minimal dependencies.
- Provides a simple and easy-to-use API.
Usage
Add the lieval crate to your Cargo.toml file:
[]
= "<version>"
Then, in your Rust code:
use *;
assert_eq!;
assert_eq!;
let mut expr = new.unwrap;
assert_eq!;
You can assign numerical values to variables and evaluate them using Context.
use *;
let mut context = new;
assert_eq!;
let mut expr = new.unwrap;
assert_eq!;
let mut expr = new.unwrap;
assert_eq!;
You can use custom functions.
use *;
let mut context = new;
assert_eq!;
assert_eq!;
You can evaluate multiple expressions separated by commas.
use *;
assert_eq!;
You can efficiently evaluate by precomputing using partial_eval.
use *;
let mut expr = new.unwrap;
expr.set_var
.set_var
.partial_eval
.unwrap;
let mut x = 1.0;
for _ in 0..10
API Documentation
Detailed API documentation can be found here.
License
This project is licensed under the MIT license.