Crates.io | calculator_util |
lib.rs | calculator_util |
version | 0.1.2 |
source | src |
created_at | 2021-12-29 07:15:22.076476 |
updated_at | 2021-12-29 08:19:55.008209 |
description | A crate that helps you evaluating mathmatical expressions. |
homepage | |
repository | https://github.com/J-ZhengLi/calculator_util/ |
max_upload_size | |
id | 504673 |
size | 26,443 |
A utility dependency that helps you solving mathmatical expressions.
This crate provide implementation for Rust's string type, thus you can evaluate math expression by simply using String.eval()
for supported format.
Add this crate as dependency to your project's Cargo.toml
.
[dependencies]
calculator_util = "0.1.2"
Evaluates a math expression.
use calculator_util::{ExprParser, number::Number};
let equation = "(5+6) * 7".to_string();
let result = equation.eval();
assert_eq!(result, Number::from(77));
println!("{}", result); // 77
Or just convert a math expression to postfix notation.
use calculator_util::ExprParser;
let equation = "1 + 2 * 3 + -4/2".to_string();
let result: String = equation.to_postfix();
println!("{}", result); // "1 2 3 * + -4 2 / +"
This crate is distributed under the terms of MIT license.
See LICENSE for details.