#calculations #expression #convert #performing #calc #solve #infix

g_calc

A small utility for performing simple math calculations using infix expression

2 releases

0.1.1 Sep 19, 2022
0.1.0 Sep 19, 2022

#1628 in Math

37 downloads per month

MIT license

8KB
143 lines

g_calc

Simple calculator utility written in rust

Installation

Add this to your Cargo.toml:

[dependencies]
g_calc = "0.1.1"

Usage

use g_calc::{convert,solve};

let sample_expr = "1 + 2 * 3";

//this fn converts the given infix expression to postfix expression
let postfix_expr = g_calc::convert(sample_expr).unwrap();

//this fn solves the postfix expression and returns the result
let output = g_calc::solve(postfix_expr).unwrap();
// output = 7    

works for basic math calculations

  • exponentiation ( ^ )
  • add, substract, multiplication, division
  • supports decimal notation ( eg., 0.1 + 0.2)
  • parentheses support ()

lib.rs:

g_calc

g_calc is a small utility to make performing calculations more convenient.

No runtime deps