expression-evaluation
Version:
Expression Evaluation
18 lines (17 loc) • 1.95 kB
JavaScript
import { FunctionDefinition, FUNCTION_ARG_MAX } from '../FunctionDefinition.js';
import { typeNumber } from '../Type.js';
export const funcAdd = new FunctionDefinition((...values) => values.reduce((acc, val) => acc + val), typeNumber, [typeNumber], 2, FUNCTION_ARG_MAX);
export const funcSubtract = new FunctionDefinition((value, subtrahend) => value - subtrahend, typeNumber, [typeNumber, typeNumber]);
export const funcNegate = new FunctionDefinition((value) => -value, typeNumber, [typeNumber]);
export const funcMultiply = new FunctionDefinition((...values) => values.reduce((acc, val) => acc *= val), typeNumber, [typeNumber], 2, FUNCTION_ARG_MAX);
export const funcDivide = new FunctionDefinition((value, divisor) => value / divisor, typeNumber, [typeNumber, typeNumber]);
export const funcRemainder = new FunctionDefinition((value, divisor) => value % divisor, typeNumber, [typeNumber, typeNumber]);
export const funcModulo = new FunctionDefinition((value, divisor) => (value % divisor + divisor) % divisor, typeNumber, [typeNumber, typeNumber]);
export const funcExponent = new FunctionDefinition((value) => Math.exp(value), typeNumber, [typeNumber]);
export const funcLogarithm = new FunctionDefinition((value) => Math.log(value), typeNumber, [typeNumber]);
export const funcPower = new FunctionDefinition((value, exponent) => Math.pow(value, exponent), typeNumber, [typeNumber, typeNumber]);
export const funcRoot = new FunctionDefinition((value, exponent) => Math.pow(value, 1 / exponent), typeNumber, [typeNumber, typeNumber]);
export const funcAbs = new FunctionDefinition((value) => Math.abs(value), typeNumber, [typeNumber]);
export const funcCeil = new FunctionDefinition((value) => Math.ceil(value), typeNumber, [typeNumber]);
export const funcFloor = new FunctionDefinition((value) => Math.floor(value), typeNumber, [typeNumber]);
export const funcRound = new FunctionDefinition((value) => Math.round(value), typeNumber, [typeNumber]);