Add std/math constants and a deterministic seedable RNG#1209
Merged
Conversation
Add the missing elementary and numeric helpers to the math module: - Float classification: isNan, isInf, isFinite, signbit, copysign, inf(), nan() - Double-returning rounding: truncD, floorD, ceilD, roundD; plus fmod, remainder, modf, frexp, ldexp - Exp/log extras: exp2, expm1, log1p - Inverse hyperbolic: asinh, acosh, atanh - Special functions: tgamma, lgamma (Lanczos), erf, erfc (Abramowitz-Stegun) - Utility: signum, lerp, fma, isqrt, array overloads of max/min - Constants: TAU, PHI, INV_PI, INV_SQRT_2 Replace the C rand() dependency with a deterministic, seedable xorshift64* generator (seed, randULong, randDouble, randDouble(min,max), randBool, randGaussian) and reimplement randInt on top of it, making randomness portable and reproducible. Cover all additions with assert-based reference tests under test/test-files/std/math. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a751dbde16
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Revert all std/math/fct.spice additions and remove their reference tests, along with the const.spice test. Keep the new math constants and the seedable RNG. Rework the randGaussian check to not depend on the removed isFinite helper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <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.
What changed
std/math/const.spice:TAU,PHI,INV_PI,INV_SQRT_2.rand()dependency instd/math/rand.spicewith a deterministic, seedable xorshift64* generator (seed,randULong,randDouble,randDouble(min,max),randBool,randGaussian); reimplementedrandInton top of it (signature unchanged).rand-extrareference test undertest/test-files/std/math/.Why
The previous RNG was a thin wrapper over platform
rand(), which is neither seedable nor reproducible. The xorshift64* generator makes randomness portable, seedable, and deterministic. The added constants round out the commonly used set.How it was validated
spicetest.rand-extratest uses range and seed-reproducibility assertions ending inprintf("All assertions passed!"), so itscout.outis the meaningful success sentinel.spicetest --gtest_filter='*std*math*'to confirm before merge.Follow-up / known limitations
randGaussianuses the Box-Muller transform; its reproducibility (not distribution shape) is what the test asserts.🤖 Generated with Claude Code