| Crates.io | shunting |
| lib.rs | shunting |
| version | 0.1.2 |
| created_at | 2017-07-19 01:54:36.853203+00 |
| updated_at | 2022-09-17 02:47:49.394365+00 |
| description | A library for evaluating math expressions |
| homepage | |
| repository | https://github.com/rodolf0/tox/tree/master/shunting |
| max_upload_size | |
| id | 24014 |
| size | 45,911 |
A library for evaluating math expressions.
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 crate also ship with the tox binary with a math repl.
$ tox
>> 4!
24
>> a = sin(0.2)^2 + cos(0.2)^2
>> a
1
>> (-3)!
NaN
>> (84 % (5/2)) !
1.32934
>> pi * 2.1^2 / cbrt(-(6+3))
-6.660512