Format + Math = Formath
Formath is a simple parser and evaluator for mathematical expressions. It can be used in tools like calculators, spreadsheets or plotters.
- Basic arithmetic operations:
+,-,*,/,% - Trigonometric functions:
sin,cos,tan,asin,acos,atan - An arbitrary number of nested parentheses:
((1 + 2) * 3) - Variables:
x,y,z, etc.
import formath
var context = new Context({"x" => 5d})
print(formath.parse("123", context).evaluate(context)) // 123
print(formath.parse("1 + 2", context).evaluate(context)) // 3
print(formath.parse("1+2 * 3", context).evaluate(context)) // 7
print(formath.parse("((x + 2) * 3)", context).evaluate(context)) // 21