feat(simulation): math, deterministic trig, RNG, clock, hasher (Phase 2, PR 3/5) - #88
Merged
Merged
Conversation
… state hasher Vector/scalar/geometry utilities, fdlibm-based sin/cos/atan2/ln using only IEEE-exact operations, xoshiro128** streams derived per the determinism spec (all published test vectors reproduced), fixed-timestep clock and a versioned 128-bit state hasher. Adds normal() vectors and accuracy notes to determinism.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2, PR 3 of 5. The deterministic building blocks the world kernel (PR 4) is made of. No
Worldbehavior yet.scalar(clamp, lerp, wrapAngle, PI constants),vector(add/sub/scale/dot/length/distance/normalize/clampLength/angle/fromAngle/lerp),geometry(rect containment, clamp to rect, circle containment/intersection, circle-rect). Pure functions, noMath.hypot.math/trig.ts): fdlibm ports ofsin,cos,atan2,lnusing only IEEE-exact operations. Domains are documented and enforced withRangeError.SeededRandom(xoshiro128**,float/integer/boolean/normal/choose,getState/setStateincluding the cached normal spare),RandomStreamsfor the six named streams, and the exact derivation from the spec ("evo-rng-v1"bytes -> FNV-1a -> splitmix32 -> state, with the all-zero fallback).SimulationClock(fixed timestep,time = tick * deltaTimeby multiplication, never accumulated).StateHasher(cyrb128-style 128-bit, big-endian float64 bits, -0 canonicalized, throws on non-finite, versioned header viaHASH_SCHEMA_VERSION), plus an exactutf8Encode(the engine cannot useTextEncoder).docs/simulation/determinism.mdgains thenormal()vectors and an accuracy statement.Simulation impact
Determinism
Math.random(), wall clock, platform transcendentals or**(ESLint enforces it on this code)Testing
Fresh clone:
install --frozen-lockfile,format:check,checkandbuildpass. 85 simulation tests (3 contracts, 24 config):float(), all-zero fallback, hasher digests including -0 canonicalization). Two of them (xoshiro reference, FNV-1a ofa) match published values, giving independent confirmation of the spec.sin/coswithin1e-15of the platform over|x| <= 1e6(including neighborhoods of multiples of pi/2),atan2within1e-15(including wildly different magnitudes and signed zeros),lnwithin2e-16relative over1e-300..1e300and near 1.worldleavesenvironmentandgeneticsuntouched), save/restore continuing the exact sequence including a cached spare, chi-square uniformity ofinteger, normal mean/sigma/tails.Review notes
normal()vectors agree exactly with aMath.logreference.|x| <= 1,000,000and throws beyond it (Payne-Hanek reduction is deliberately not implemented; the engine wraps angles).World/ENGINE_VERSIONinindex.tsare untouched; PR 4 replaces them.🤖 Generated with Claude Code