#expression-evaluator #evaluator #polish #expression #reverse

yanked polishexpr

A poorly implementation of a polish reverse expression evaluator

2 releases

0.1.4 Dec 10, 2023
0.1.2 Dec 9, 2023
0.1.1 Dec 9, 2023
0.1.0 Dec 9, 2023

#28 in #polish

MIT license

10KB
166 lines

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);

lib.rs:

PolishEvaluator

Poor implementation of of polish expression evaluator

Evaluator of expressions written in reverse polish notation. 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.

Examples

use polishexpr::PolishEvaluator;

let pe = PolishEvaluator::new("$0 $1 +", &[2.0, 2.0]);
let result = pe.evaluate().expect("get the sum result");
assert_eq!(4.0, result);

No runtime deps