Function

nerdamer.buildFunction

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

Compiles an expression into a native JavaScript-number function.

remarks

This intentionally uses dynamic JavaScript function construction and may be unavailable under a strict Content Security Policy. It favors native-number throughput over Nerdamer's exact or arbitrary-precision arithmetic. Scalar function calls are linked to explicit numerical implementations; symbolic-only or structured operations that survive to this stage are rejected rather than compiled incorrectly. When

`argsArray`

is omitted, variable names are sorted alphabetically.

throws

UnsupportedOperationError If a surviving function has no faithful JavaScript-number implementation.

Parameters

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

Returns

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

Examples

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