agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
42 lines (41 loc) • 2.18 kB
TypeScript
/** The shared precision rule for existing figures and opt-in plain decimals,
* and the one exact reading of a number written in scientific notation. */
/** Decimal places the answer wrote the value with. */
export declare function decimalsOf(value: string): number;
/** A source spelling is kept only within this bound, never silently clipped. */
export declare const MAX_ROUNDING_SPELLING_CHARS = 256;
/** The decimal a scientific spelling states, read exactly. */
export interface ScientificDecimal {
/** The value with no exponent and no trailing fractional zero:
* `1.12e-02` → `0.0112`, `3.358e+03` → `3358`. */
readonly exact: string;
/** The value at the precision the spelling was written with, only when
* that is a fraction: `1.120e-2` → `0.01120`. A spelling with no
* fractional places after expansion (`3.358e+03`) has none — it is
* matched exactly, never rounded. */
readonly written?: string;
}
/**
* Read one standalone scientific spelling as the decimal it states — exactly,
* through `decimalOf` (BigInt, no Number conversion) and within its bounds:
* the spelling at most `MAX_ROUNDING_SPELLING_CHARS` characters, its exponent
* within ±400, and the decimal it states within the same character bound.
* `undefined` for any other token; outside the bounds a token stays a
* spelling only.
*
* @example
* ```ts
* scientificDecimalOf('1.12e-02'); // { exact: '0.0112', written: '0.0112' }
* scientificDecimalOf('1.2E+21'); // { exact: '1200000000000000000000' }
* scientificDecimalOf('9f3e10ab'); // undefined — a hash, not a number
* ```
*/
export declare function scientificDecimalOf(spelling: string): ScientificDecimal | undefined;
/** True inside the answer's inclusive half-unit rounding interval.
* Existing figures keep their exact historical numeric allowance. New plain
* decimals supply original spellings and use the same interval without slack
* or lossy Number subtraction. There is one rounding rule and one owner. */
export declare function roundsTo(x: number, f: number, decimals: number, spellings?: {
readonly source: string;
readonly answer: string;
}): boolean;