The CLI calculator you never knew you needed. Also usable as a library!
Call with an expression to evaluate:
$ calc "42*atan(pi/2)" 42.163162517863
Or call without arguments to go interactive:
$ calc ~ 42*atan(pi/2) 42.163162517863
As simple as falling off a rock:
use NoccyLabs\PhpCalc\Calculator; $calc = new Calculator(); $result = $calc->evaluate("42 * atan(pi/2)");
What it does
^exponent/raise to power
- You can set the precision using the
_pvariable. If the expression is passed on the command line, prepend the variable followed by a semicolon, such as
_p=2;pifor the result 3.14.
Bugs and known issues
- Negative numbers and subtraction should be surrounded by whitespace to parse properly.
2-1will result in
-1, returning 2 and a warning. Passing
2 - 1will return
1as expected, as will