Function

nerdamer.buildFunction

src/index.ts:815
nerdamer.buildFunction(x: ExpressionInput, argsArray?: string[]): (...args: number[]): number

Compiles an expression into a native JavaScript-number function for repeated evaluation.

remarks

Function calls are linked to Nerdamer's numerical implementations, including any dependencies they require. The compiler supports scalar JavaScript-number arithmetic rather than Nerdamer's full symbolic or structured value model. Symbolic-only operations such as indexed sums, products, solvers, and matrix operations are rejected if they remain in the expression. buildFunction uses new Function, so it may be unavailable under a Content Security Policy that forbids dynamic JavaScript evaluation. When argsArray is omitted, free variables are sorted alphabetically.

throws

core!UnsupportedOperationError If the expression contains the imaginary unit or a function for which no matching JavaScript-number implementation is registered.

Parameters

NameTypeDescription
xExpressionInputThe expression to compile.
argsArraystring[]Variable names in the positional order expected by the compiled function.

Returns

(...args: number[]): number — The compiled JavaScript-number function.

Examples

buildFunction('x-y')(9, 7);                // 2
buildFunction('x-y', ['y', 'x'])(9, 7);    // -2
buildFunction('erf(x)+2')(9);              // 3