Function calc::eval_polish [] [src]

pub fn eval_polish(input: &str) -> Result<Value, CalcError>

Evalulates mathematical expressions that are written in Polish Notation.

Polish Notation defines that a string of operators are given at the beginning of the expression, as prefixes, and are followed by a string of numbers to apply each operation to. Polish Notation enables writing mathematical expressions that don't require grouping via parenthesis. It's also referred to as Prefix Notation, or Normal Polish Notation (NPN).

Examples

  • + * 3 4 5 is equivalent to 3 * 4 + 5
  • + / * 5 3 2 * + 1 3 5 is equivalent to ((5 * 3) / 2) + ((1 + 3) * 5)