Files
scriptc/tests/corpus/1112-number-methods.ts
Chris Tate bc2cd2b7d1 Support Number.toFixed statically
- Lower Number.prototype.toFixed through the compiler IR and native backends.
- Match JavaScript rounding, range errors, and numeric edge cases in the runtime.
- Add differential coverage and update surface metadata and diagnostics.
2026-07-26 18:43:53 -05:00

18 lines
896 B
TypeScript

// @dynamic
// Explicit toFixed is static; toPrecision/toString(radix) execute in the
// island. The receiver marshals by value there and the engine auto-boxes
// it, so `this` binds the number exactly as in JS. All stay byte-exact
// differential.
const n = 1234.5678;
console.log(n.toFixed(0), n.toFixed(2), n.toFixed(6));
console.log((0.1 + 0.2).toFixed(17), (-3.7).toFixed(1), (0).toFixed(2));
console.log((1e21).toFixed(2), (0 / 0).toFixed(2));
console.log(n.toPrecision(2), n.toPrecision(8), (0.000123).toPrecision(2));
console.log((255).toString(16), (255).toString(2), (511).toString(8), (12345).toString(36));
console.log((-255).toString(16), (0.5).toString(2));
const digits = 3;
console.log(Math.PI.toFixed(digits));
// Results are ordinary static strings: length, concat, further island calls.
const hex = (48879).toString(16);
console.log(hex.length, hex.toUpperCase(), "0x" + hex);