Evaluate a mathematical expression by using the Shunting-yard algorithm to parse the input into a Reverse Polish notation.
$ ./calc
Expression: 23 + 6 * (4 / 3!) ^ -0.51 + ln(21)
Result: 33.42284763163235
- + addition
- - subtraction
- * multiplication
- / division
- ^ exponentiation
- ! factorial
- % modulus
- abs(x) absolute value
- sqrt(x) square root
- ln(x) natural logarithm
- log(x,y) logarithm in base x of y
- sin(x) sine of angle in radians
- cos(x) cosine of angle in radians
- tan(x) tangent of angle in radians
- asin(x) arcsine of angle in radians
- acos(x) arccosine of angle in radians
- atan(x) arctangent of angle in radians
- { [ ( ) ] }
- pi ratio of a circumference to the diameter
- e Euler’s constant
- -h to show the help
Additional functions can be easily implemented by adding its name and the corresponding character to the func
vector and the character with the actual function pointer to either map1
or map2
map, depending on the number of arguments.