2 releases (1 stable)

1.0.0 Dec 13, 2021
0.0.7 Nov 13, 2020

#154 in Parser tooling

36 downloads per month

MIT license

33KB
752 lines

Documentation

A library for evaluating math expressions.

Published Versions

The trimmed shunting crate has has its latest version pushed to crates.io as thin-shunting

Using the library

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);
}

A MathContext

MathContext allows keeping context across multiple invocations to parse and evaluate. You can do this via the setvar method.

Credit

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.

Dependencies

~520KB