Skip to content
Pieter De Rycke edited this page Jul 19, 2018 · 4 revisions

Custom functions are supported in Jace.NET 0.8 and higher. They allow programmers to add additional functions besides the ones already supported (sin, cos, asin, …). Functions are required to have a unique name (this name is case insensitive). The existing functions cannot be overwritten.

Examples

Adding a function for calculating the largest integer less than or equal to the specified value:

CalculationEngine engine = new CalculationEngine();
engine.AddFunction("floor", (Func<double, double>)((a) => Math.Floor(a))):
double result = engine.Calculate("floor(42.428)");

Adding a function for calculating the sum of a dynamic list of parameters:

CalculationEngine engine = new CalculationEngine();

double Sum(params double[] a)
  {
    return a.Sum();
  }

engine.AddFunction("sum", Sum);
double result = engine.Calculate("sum(1,2,3,4,5,6,7,8,9,10,11)");
Clone this wiki locally