/** * ToNumericPrimitive decision kernel — slice 0.75 substrate. * * A dependency-free, browser-safe pure-TS module that answers KERN's * ToNumber question for the FROZEN primitive domain (numbers, ECMA numeric * strings, booleans, null, and the `undefined` sentinel) and built-on integer * coercions (`toInt32` / `toUint32` / `toIntegerOrInfinity`). It is one of the * three artifacts of a slice-0.75 contract (charter §A.1): the kernel operates * on *semantic values*, never on text or ValueIR, and never imports `typescript` * or anything heavy. * * Why a real grammar (not `Number(...)` delegation): * The kernel is the executable SPEC the differential battery validates * against native JS `Number()`. Delegating to `Number()` would make the * self-test tautological AND would not transfer to Python — Python's * `float()` diverges from JS on three load-bearing cases: it accepts numeric * separators (`float("1_000") === 1000.0`), case-insensitive infinity/NaN * words (`float("infinity")`, `float("nan")`), and raises on `0x`/`0b`/`0o` * prefixes. So both the TS kernel here and the emitted Python helper encode * the ECMA-262 StringNumericLiteral grammar explicitly; the battery proves * they agree with each other and with `Number()`. * * Fail-closed boundary (charter §A; oracle "Fail-Closed List"): * Objects, arrays, functions, symbols, bigints, and custom-`valueOf` hosts * are NOT coerced — full ToPrimitive (valueOf/toString ordering, array * stringification) is out of slice scope. They return the discriminated * `{ ok: false }` variant so the CALLER decides (diagnostic vs. throw), per * the charter's "fail-closed result, NOT a throw-by-default" rule. * * Float mandate (tribunal amendment 1): every numeric output is a JS double * (the only number type JS has), so the Python twin must return `float` for * every numeric result including bool/null/hex inputs. `-0` sign is preserved * (amendment 2). */ /** A value the kernel will coerce. Exotic hosts fall into the fail-closed branch. */ export type KernNumericInput = unknown; /** * Result of a ToNumber-family coercion. * * - `{ ok: true, value }` — a successful numeric result. For `toNumber`, * `value` is a JS number (may be `NaN`, `±Infinity`, or `-0`). For the * integer codomains it is an integer (`toInt32`/`toUint32`) or an * integer-valued number / `±Infinity` (`toIntegerOrInfinity`). * - `{ ok: false, reason }` — the input is outside the slice-0.75 primitive * domain (object/array/function/symbol/bigint/custom-valueOf). The caller * decides how to surface it (compile-time diagnostic or runtime refusal); * the kernel never throws for this case. */ export type NumericResult = { readonly ok: true; readonly value: number; } | { readonly ok: false; readonly reason: string; }; /** * The sentinel a host passes for KERN `undefined`. The kernel recognizes the * JS primitive `undefined` directly; an explicit object sentinel can also be * tagged by callers using {@link isUndefinedSentinel}. Kept as a unique symbol * so it can never collide with a user value. */ export declare const KERN_UNDEFINED_SENTINEL: unique symbol; /** * The exact set of code points ECMA-262 trims from both ends of a * StringNumericLiteral: `StrWhiteSpace` = `WhiteSpace` ∪ `LineTerminator`. * Verified against V8 `Number(ws + "5" + ws) === 5` for every member, and * against the *exclusions* `U+200B` (ZWSP), `U+0085` (NEL), `U+180E` which JS * does NOT trim. * * Order/membership is load-bearing: the Python twin embeds the identical set. */ export declare const ECMA_STR_WHITESPACE: readonly number[]; /** * ECMA-262 `StringToNumber` over a StringNumericLiteral. * * Returns a JS number, using `NaN` for any string outside the grammar. Empty * and all-whitespace strings are `+0`. `-0` survives. `"Infinity"` is * case-sensitive (only the exact word, optionally signed). Radix prefixes * `0x`/`0b`/`0o` (any case) are unsigned-only. */ export declare function stringToNumber(raw: string): number; /** * ECMA-262 `ToNumber` restricted to the slice-0.75 primitive domain. * * number → itself (NaN, ±Infinity, -0 preserved) * boolean → 1 / 0 * null → +0 * undefined → NaN (JS primitive `undefined` or {@link KERN_UNDEFINED_SENTINEL}) * string → {@link stringToNumber} * else → fail-closed `{ ok: false }` (object/array/function/symbol/bigint) */ export declare function toNumber(x: KernNumericInput): NumericResult; /** ECMA-262 `ToInt32`: ToNumber then modular wrap to signed 32-bit. */ export declare function toInt32(x: KernNumericInput): NumericResult; /** ECMA-262 `ToUint32`: ToNumber then modular wrap to unsigned 32-bit. */ export declare function toUint32(x: KernNumericInput): NumericResult; /** * ECMA-262 `ToIntegerOrInfinity`: ToNumber then truncate toward zero. * `NaN → +0`; `±Infinity → ±Infinity`; otherwise the integer part (a number, * not necessarily int32-ranged). */ export declare function toIntegerOrInfinity(x: KernNumericInput): NumericResult; /** Signed 32-bit modular wrap of an already-numeric value (shift-mask domain). */ export declare function numberToInt32(value: number): number; /** Unsigned 32-bit modular wrap of an already-numeric value. */ export declare function numberToUint32(value: number): number; /** Truncate toward zero, mapping NaN→+0 and preserving ±Infinity. */ export declare function numberToIntegerOrInfinity(value: number): number;