calculator_util 0.1.2

A crate that helps you evaluating mathmatical expressions.
Documentation
  • Coverage
  • 80%
    20 out of 25 items documented19 out of 21 items with examples
  • Size
  • Source code size: 26.44 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 505.77 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • J-ZhengLi/calculator_util
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • J-ZhengLi

calculator_util

A utility dependency that helps you solving mathmatical expressions.

Crate

This crate provide implementation for Rust's string type, thus you can evaluate math expression by simply using String.eval() for supported format.

Usage

Add this crate as dependency to your project's Cargo.toml.

[dependencies]
calculator_util = "0.1.2"

Example:

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 / +"

License

This crate is distributed under the terms of MIT license.

See LICENSE for details.