-
Notifications
You must be signed in to change notification settings - Fork 7
Getting Started
Brandon Wood edited this page May 29, 2014
·
2 revisions
The following page is focused on understanding how to use dotMath in your application and get up and running in the shortest amount of time.
var compiler = new EquationCompiler("4+3");
double value = compiler.Calculate();
Evaluation an expressions with variables requires setting the variables' values before performing the Calculate()
step.
var compiler = new EquationCompiler("a+b");
compiler.SetVariable("a", 4);
compiler.SetVariable("b", 3);
double value = compiler.Calculate();
The dotMath library allows the user to define their own functions. In this example, we'll define a simple 'factorial' function.
var compiler = new EquationCompiler("factorial(5)");
compiler.AddFunction("factorial", x =>
{
int factorial = 1;
for (int i = 1; i <= x; i++)
{
factorial *= i;
}
return factorial;
});
double value = compiler.Calculate();