Skip to content

alirezamdk/evalMathExpression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔢    Eval Math Expression

A simple library for evaluating mathematical expressions in Rust.

🔧      Installation

To use this library in your project, you need to add the evalmath source code to your project, and then add extern crate evalmath to the crate root file, and use evalmath::calculate in the code.

💻    Usage

extern crate evalmath;
use evalmath::calculate;

fn main() {
    let expr = "-6 + 6 * 6";
    let result = calculate!(expr);
    match result {
        Ok(res) => println!("{} = {}",expr, res),
        Err(e) => println!("Error: {}", e),
    }
}

This will output: -6 + 6 * 6 = 36
Note: This example is just a basic example, the library support more advanced mathematical expressions.

Want to see evalmath in action? Simply run cargo run --example main.rs in project root

📚    Supported Operators and Functions

  • The library supports all common mathematical operators such as +, -, *, /, ^, !, etc.
  • It also supports a wide range of mathematical functions like sqrt, log, ln, floor, sin, cos, sinh, cosh, tan, tanh, abs, max, min, var, round, etc...
  • It also supports conversion functions like bin, hex, oct, etc...

You can find a complete list of supported operators and functions in the tokens.rs file, specifically in the TokenType enum.

📝    Notation Support

This library can convert mathematical expressions to a tree, postfix, and prefix notation, and display the results in a user-friendly way.

🚫    Limitations

  • Only support f64 numbers
  • Only support basic mathematical operations, for example does not support adding functions or variables for now

🌳    Algorithms

This library by defualt use the Shunting Yard algorithm for evaluating. Additionally, it also supports expression tree, Direct Algebraic Logic (DAL) algorithm.

🤗    Contributions

Got an idea or a fix? I'm all ears! :)

⚠️    Note

Please note that this library is in an early stage of development. Use at your own risk.

📜    License

This project is licensed under the MIT License

Releases

No releases published

Packages

No packages published

Languages