Reverse Polish notation (RPN) is a mathematical notation in which every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position.
// 1 + 2 = 3
input('1 2 +'); // 3
// 1 + 2 - 3 = 0
input('1 2 + 3 -'); // 0
// (1 + 2) * 3 = 9
input('1 2 + 3 *'); // 9
operator | operation | example |
---|---|---|
+ |
addition | 1 2 + = 3 |
- |
subtraction | 1 2 - = -1 |
* |
multiplication | 2 3 * = 6 |
/ |
division | 7 2 / = 3.5 |