opencode/packages/codemode-rust/conformance/cases/std-number-format-random.js
kommander ebb15aeb19 feat(codemode): add URI functions, toExponential, Math.sumPrecise, f16round and copyWithin
- encodeURI/encodeURIComponent/decodeURI/decodeURIComponent with the
  reference's URIError messages.
- Number formatting follows JavaScriptCore: toString(radix) ports its exact
  integer digits and shortest-fraction algorithm, toExponential and
  toPrecision round half up on the exact value, toFixed keeps the sign of
  a negative that rounds to zero, and number-to-string picks the even
  digit when two shortest forms tie. Range errors use the host messages.
- Math.sumPrecise sums exactly and rounds once; Math.f16round rounds
  straight from the double; Array.prototype.copyWithin.

Number-to-string and its tie rule live in value.rs, so integers from 2^53
up print their shortest digits instead of every digit.

copyWithin converts its arguments through ToPrimitive like the other Array methods. Number-to-string decides ties in 128-bit integer arithmetic. test262: the reference's skipped.txt drops three copyWithin files the reference passes.
2026-11-18 18:56:09 +01:00

10 lines
433 B
JavaScript

let seed = 12345
const rnd = () => { seed = (seed * 1103515245 + 12345) % 2147483648; return seed / 2147483648 }
const out = []
for (let i = 0; i < 400; i++) {
const x = (rnd() - 0.5) * 10 ** Math.floor(rnd() * 40 - 20)
const r = 2 + Math.floor(rnd() * 35)
const d = Math.floor(rnd() * 20)
out.push([x.toString(r), x.toExponential(d), x.toPrecision(d + 1), x.toFixed(d), x.toExponential(), String(x)].join("|"))
}
return out