evaluatorrs 0.0.1

Tools for runtime evaluation of mathematical expressions
Documentation
  • Coverage
  • 100%
    85 out of 85 items documented3 out of 60 items with examples
  • Size
  • Source code size: 123.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 15.24 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Rosdf/evaluatorrs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Rosdf

This library provides ways to evaluate mathematical expressions at runtime.

Feature switches

  • std (default): enables use of std library
  • libm: enables use of mathematical functions from libm, useful for no_std crates and non-standard functions

Example 1

use evaluatorrs::eval;
use evaluatorrs::formulas::ParserError;

fn evaluate() -> Result<(), ParserError> {
    let expression = "1 + 2";
    let result = eval(expression)?;
    debug_assert_eq!(result, 3.0);
    Ok(())
}

Example 2

use evaluatorrs::formulas::{Evaluate, RootFormula};
use evaluatorrs::function_stores::EmptyFunctionStore;
use evaluatorrs::variable_stores::{HashMapVariableStore, SetVariable};

fn example() -> Result<(), ParserError> {
    let formula = RootFormula::parse("a + b", &EmptyFunctionStore)?;
    let mut variable_store = HashMapVariableStore::new();
    variable_store.set("a", RootFormula::parse("1", &EmptyFunctionStore)?);
    variable_store.set("b", RootFormula::parse("10", &EmptyFunctionStore)?);
    let evaluated = formula.eval(&variable_store);
    assert!(evaluated.is_ok());
    let evaluated = evaluated?;
    assert_eq!(evaluated, 11.0);
 }