/** * Built-in mathematical & statistical functions. * * Two small abstract bases remove repeated arity/coercion boilerplate while * still giving every function its own class (per the engine's extension model): * {@link NumericAggregateFunction} for range-consuming reducers (SUM, AVERAGE, …) * and {@link UnaryMathFunction} for single-number transforms (ABS, SQRT, …). * * @packageDocumentation */ import type { FormulaFunction } from './formula-function'; import { FunctionCategory } from './formula-function'; import type { EvalContext } from '../types/eval-context'; import type { FormulaArgument, FormulaValue } from '../types/formula.types'; /** * Base for functions that reduce all numeric operands (flattening ranges, per * Excel's range-vs-literal rule) to a single value. */ declare abstract class NumericAggregateFunction implements FormulaFunction { abstract readonly name: string; readonly category = FunctionCategory.Math; readonly minArgs = 1; readonly maxArgs: number; evaluate(args: readonly FormulaArgument[]): FormulaValue; /** Combines the collected numbers into the result. */ protected abstract reduce(nums: readonly number[]): FormulaValue; } /** Base for single-argument numeric transforms. */ declare abstract class UnaryMathFunction implements FormulaFunction { abstract readonly name: string; readonly category = FunctionCategory.Math; readonly minArgs = 1; readonly maxArgs = 1; evaluate(args: readonly FormulaArgument[]): FormulaValue; /** Transforms the coerced numeric input. */ protected abstract compute(n: number): FormulaValue; } /** `SUM(number1, [number2], …)` — adds all numeric operands. */ export declare class SumFunction extends NumericAggregateFunction { readonly name = "SUM"; readonly description = "Adds all numbers in the given range(s) and/or values."; protected reduce(nums: readonly number[]): FormulaValue; } /** `AVERAGE(number1, …)` — arithmetic mean; `#DIV/0!` when there are no numbers. */ export declare class AverageFunction extends NumericAggregateFunction { readonly name = "AVERAGE"; readonly description = "Returns the average (arithmetic mean) of the numbers."; protected reduce(nums: readonly number[]): FormulaValue; } /** `MIN(number1, …)` — smallest number, or `0` when there are none (Excel). */ export declare class MinFunction extends NumericAggregateFunction { readonly name = "MIN"; readonly description = "Returns the smallest number in a set of values."; protected reduce(nums: readonly number[]): FormulaValue; } /** `MAX(number1, …)` — largest number, or `0` when there are none (Excel). */ export declare class MaxFunction extends NumericAggregateFunction { readonly name = "MAX"; readonly description = "Returns the largest number in a set of values."; protected reduce(nums: readonly number[]): FormulaValue; } /** `COUNT(value1, …)` — counts how many operands are numbers. */ export declare class CountFunction extends NumericAggregateFunction { readonly name = "COUNT"; readonly description = "Counts how many of the given values are numbers."; protected reduce(nums: readonly number[]): FormulaValue; } /** `COUNTA(value1, …)` — counts non-blank operands (any type, including errors). */ export declare class CountAFunction implements FormulaFunction { readonly name = "COUNTA"; readonly category = FunctionCategory.Math; readonly minArgs = 1; readonly maxArgs: number; readonly description = "Counts the number of non-empty values."; evaluate(args: readonly FormulaArgument[]): FormulaValue; } /** `ABS(number)` — absolute value. */ export declare class AbsFunction extends UnaryMathFunction { readonly name = "ABS"; readonly description = "Returns the absolute value of a number."; protected compute(n: number): FormulaValue; } /** `SQRT(number)` — square root; `#NUM!` for negatives. */ export declare class SqrtFunction extends UnaryMathFunction { readonly name = "SQRT"; readonly description = "Returns the positive square root of a number."; protected compute(n: number): FormulaValue; } /** Shared arity/coercion for the `ROUND*` family (number, [digits]). */ declare abstract class RoundingFunction implements FormulaFunction { abstract readonly name: string; readonly category = FunctionCategory.Math; readonly minArgs = 1; readonly maxArgs = 2; evaluate(args: readonly FormulaArgument[]): FormulaValue; protected abstract round(n: number, digits: number): FormulaValue; } /** `ROUND(number, [digits])` — round half away from zero. */ export declare class RoundFunction extends RoundingFunction { readonly name = "ROUND"; readonly description = "Rounds a number to a specified number of digits."; protected round(n: number, digits: number): FormulaValue; } /** `ROUNDUP(number, [digits])` — round away from zero. */ export declare class RoundUpFunction extends RoundingFunction { readonly name = "ROUNDUP"; readonly description = "Rounds a number up, away from zero."; protected round(n: number, digits: number): FormulaValue; } /** `ROUNDDOWN(number, [digits])` — round toward zero. */ export declare class RoundDownFunction extends RoundingFunction { readonly name = "ROUNDDOWN"; readonly description = "Rounds a number down, toward zero."; protected round(n: number, digits: number): FormulaValue; } /** `POWER(base, exponent)` — `base` raised to `exponent`. */ export declare class PowerFunction implements FormulaFunction { readonly name = "POWER"; readonly category = FunctionCategory.Math; readonly minArgs = 2; readonly maxArgs = 2; readonly description = "Returns the result of a number raised to a power."; evaluate(args: readonly FormulaArgument[]): FormulaValue; } /** `RAND()` — a uniform random number in `[0, 1)`. Volatile. */ export declare class RandFunction implements FormulaFunction { readonly name = "RAND"; readonly category = FunctionCategory.Math; readonly minArgs = 0; readonly maxArgs = 0; readonly volatile = true; readonly description = "Returns a random number between 0 and 1."; evaluate(_args: readonly FormulaArgument[], ctx: EvalContext): FormulaValue; } /** `RANDBETWEEN(low, high)` — a random integer in `[low, high]`. Volatile. */ export declare class RandBetweenFunction implements FormulaFunction { readonly name = "RANDBETWEEN"; readonly category = FunctionCategory.Math; readonly minArgs = 2; readonly maxArgs = 2; readonly volatile = true; readonly description = "Returns a random integer between two values (inclusive)."; evaluate(args: readonly FormulaArgument[], ctx: EvalContext): FormulaValue; } export {}; //# sourceMappingURL=math-functions.d.ts.map