@lp-labs/interpolation-table
v0.1.0
Published
Bounded, dependency-free interpolation table algorithms with explicit numerical failure handling.
Readme
@lp-labs/interpolation-table
Copied sorted interpolation tables with linear and left-held step evaluation and no implicit extrapolation.
Standalone Node.js >=18 package. ESM and CommonJS with separate strict TypeScript declarations. No runtime, peer or sibling dependencies.
Install
npm install @lp-labs/interpolation-tableExample
import { createTable } from '@lp-labs/interpolation-table';
const table = createTable([0, 1, 3], [0, 2, 6]);
console.log(table.evaluate(2)); // 4
const step = createTable([0, 1, 3], [0, 2, 6], 'step');
console.log(step.evaluate(2)); // 2API, customization, numerical behavior and limits
createTable(xs,ys,mode='linear') requires 2..100000 equal-length finite arrays, strictly increasing unique xs and a valid InterpolationMode. Inputs are copied. InterpolationTable.evaluate(x) binary-searches the interval; exact knot values return the supplied y, including the last knot. linear uses convex endpoint weights (not a potentially overflowing y difference); step holds the left sample between knots, with right-continuous values at knots. No extrapolation: values outside the domain throw RangeError. Nonfinite queries throw TypeError; invalid tables throw RangeError and unknown mode TypeError. Coordinate normalization is used only if subtracting finite endpoints would overflow. Finite intermediate/output checks reject overflow; ordinary floating-point rounding remains, especially when coordinates are nearly equal or mixed across extreme scales. No monotone cubic, smoothing or derivative claims. Construction O(N) time/memory, evaluation O(log N) time and O(1) auxiliary memory. No callbacks or extrapolation customization.
Full declarations
export type InterpolationMode = 'linear' | 'step';
export interface InterpolationTable {
evaluate(x: number): number;
}
export declare function createTable(
xs: readonly number[],
ys: readonly number[],
mode?: InterpolationMode,
): InterpolationTable;Development
npm ci --offline --no-audit --no-fund
npm run build
npm run typecheck
npm test
npm run format:checkTests use Node's built-in runner and include independent or analytic reference cases. No runtime global browser access, I/O or hidden dependencies.
Support
If this library is useful to you, consider supporting its maintenance with a donation via PayPal.
Author
Created by Libin Prasanth. Connect on LinkedIn for updates and discussion.
