#arithmetic #calculator #parser #maths

math-calc

A simple text-based arithmetic library

1 unstable release

0.1.0 Sep 18, 2019

#43 in #maths

41 downloads per month
Used in math-calc-cli

MIT license

6KB

math-calc

math-calc or "Arithmetic Calculator" is a simple, text-based arithmetic library that focuses on calculation chaining.

This means you can input multiple arithmetic operations at once and quickly calculate the result. For example, (10 + 60) / 5, 4 + 20 would result in [14, 24].

Documentation

The documentation for this arithmetic calculator can be found here on Doc.rs.

Repository

The source code is hosted on GitLab and can be found here.


lib.rs:

About

Welcome to the documentation for math-calc! This is a simple arithmatic library that gets an inputted [String], [u8] slice or a plain &str and outputs the finished calculation.

This essentially means you can input multiple calculations seperated by a , (similar to how JSON can be used) and get a [Vec]<[i32]> containing the finished calculations.

Examples

A basic parsing of a &str directly:

use math_calc::{ErrorKind, parse_str};

fn main() {
    // Expected returns: 1st: 3, 2nd: 110, 3rd: 123
    let inputted_calculations = "1 + 2, 550 / 5, 8 * 16 + (-25 / 5)";
    
    // Generate results
    let output_vec: Vec<i32> = parse_str(inputted_calculations).unwrap();

    // Output results of calculation
    println!("Calculation results (in vector):\n\n{:?}", output_vec);
}

Dependencies

~2.1–4MB
~69K SLoC