| Crates.io | thin-shunting |
| lib.rs | thin-shunting |
| version | 1.0.0 |
| created_at | 2020-11-13 16:57:46.879351+00 |
| updated_at | 2021-12-13 12:36:31.89557+00 |
| description | A library for evaluating math expressions |
| homepage | |
| repository | https://github.com/rodolf0/tox/tree/master/shunting |
| max_upload_size | |
| id | 312012 |
| size | 32,082 |
A library for evaluating math expressions.
The trimmed shunting crate has has its latest version pushed to crates.io as thin-shunting
fn main() {
let input = "sin(0.2)^2 + cos(0.2)^2";
let expr = ShuntingParser::parse_str(input).unwrap();
let result = MathContext::new().eval(&expr).unwrap();
println!("{} = {}", expr, result);
}
MathContext allows keeping context across multiple invocations to parse and evaluate. You can do this via the setvar method.
The vast majority of the work here was done by Rodolfo Granata warlock.cc@gmail.com, I've just trimmed things down and cleaned up the code a little.