In reverse Polish notation operators are appended after their operands, eliminating the need for brackets.
$ calc 3 2 +
5
Accepts command line arguments, as well as stdin:
$ echo "3 2 +" | calc
5
Note The naming of all operators is case insensitive
Constants:
pi
Archimedes’ constant πe
Euler's constant e
Operators that take one input value:
ln
Loagaritm base elog2
Logarithm base 2log10
Logarithm base 10sin
Sinecos
Cosinetan
Tangent
Operators that take two input values:
+
Addition-
Subtraction.
Multiplication (Note that.
is used for multiplication, because*
represents a wildcard in bash)/
Divisionlog
Logarithm with given base
Invalid tokens are ignored for computation, but give a warning.
$ calc 3 __ 7 + ?? 6 /
Warning: expression contains 2 invalid tokens
│ calc 3 __ 7 + ?? 6 /
└────────^^─────^^────
An expression can not be computed if an operator does not have enough values on the stack to complete its operation...
$ calc 3 +
Error: not enough values on stack to apply operator
│ calc 3 +
└────────^
...or if at the end of the computation more than one value remains on the stack.
$ calc 3 5 7 +
Error: stack contains more than one value after applying all operators