polishexpr

Crates.iopolishexpr
lib.rspolishexpr
version0.1.4
sourcesrc
created_at2023-12-09 18:56:28.113733
updated_at2023-12-10 02:14:19.038247
descriptionA poorly implementation of a polish reverse expression evaluator
homepagehttps://github.com/jgardona/polishexpr
repositoryhttps://github.com/jgardona/polishexpr
max_upload_size
id1063833
size10,339
Júlio César de Brito Gardona (jgardona)

documentation

README

polishexpr

A poorly implemented polish reverse expression evaluator.

The list of supported functions are:

  • Arithmetic functions: +, -, *, /
  • sin: sine
  • cos: cosine
  • ln: natural logarithm
  • exp: exponent
  • sqrt: square root

Arguments for these functions could be as usual constants, written as numbers, as variables, written as $var_number ($0, for example). The variable number is zero based index of variables vector.

Usage

  • Sums 2+2 and equals 4
let pe = PolishEvaluator::new("$0 2 +", &[2.0]);
let result = pe.evaluate()?;
assert_eq!(4f64, result);
  • Evaluate 2 + 3 - 5
let pe = PolishEvaluator::new("$0 $1 + $3 -", &[2.0, 3.0, 5.0]);
let result = pe.evaluate()?;
assert_eq!(0f64, result);
Commit count: 11

cargo fmt