thin-shunting

Crates.iothin-shunting
lib.rsthin-shunting
version1.0.0
created_at2020-11-13 16:57:46.879351+00
updated_at2021-12-13 12:36:31.89557+00
descriptionA library for evaluating math expressions
homepage
repositoryhttps://github.com/rodolf0/tox/tree/master/shunting
max_upload_size
id312012
size32,082
Brooks Rady (TheLostLambda)

documentation

README

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.

Commit count: 693

cargo fmt