fasteval3 3.0.1

Fast evaluation of algebraic expressions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// usage:  cargo run --release --example ns_callback

fn main() -> Result<(), fasteval3::Error> {
    let mut num_lookups = 0;
    let mut cb = |name: &str, _args: Vec<f64>| -> Option<f64> {
        num_lookups += 1;
        match name {
            "x" => Some(2.0),
            _ => None,
        }
    };

    let val = fasteval3::ez_eval("x * (x + 1)", &mut cb)?;
    assert!((val - 6.0).abs() < f64::EPSILON);
    assert_eq!(num_lookups, 2); // Notice that 'x' was looked-up twice.

    Ok(())
}