Mathew 0.0.2: Math, on float, evaluator

#1

Mathematical expression evaluator with context and float methods

use mathew::Eval;

fn main() -> Result<(), ()> {
    let e = Eval::default().insert("foo", "1")?.insert("bar", "0")?;

    assert_eq!(e.eval("foo + bar").unwrap(), 1.0);
    
    assert_eq!(e.eval("foo - bar * 1").unwrap(), 1.0);
    
    assert_eq!(e.eval("1 + bar").unwrap(), 1.0);
    
    assert_eq!(e.eval("2.5.powi(2 * foo)").unwrap(), 6.25);

    Ok(())
}

I hope it’s helps.
https://crates.io/crates/mathew

3 Likes
#2

That’s nice!

Why are you using methods instead of operators / stand alone function ?
To be more compatible with the Rust syntax ?

#3

Because I recycled that part of crate v_eval, use syn, and it was easier to integrate it.

Although it is better with methods!

Thanks for the support!