Skip to content

Add std/math constants and a deterministic seedable RNG#1209

Merged
marcauberer merged 3 commits into
mainfrom
std/extend-math-library
Jun 15, 2026
Merged

Add std/math constants and a deterministic seedable RNG#1209
marcauberer merged 3 commits into
mainfrom
std/extend-math-library

Conversation

@marcauberer

@marcauberer marcauberer commented Jun 15, 2026

Copy link
Copy Markdown
Member

What changed

  • Added constants to std/math/const.spice: TAU, PHI, INV_PI, INV_SQRT_2.
  • Replaced the C rand() dependency in std/math/rand.spice with a deterministic, seedable xorshift64* generator (seed, randULong, randDouble, randDouble(min,max), randBool, randGaussian); reimplemented randInt on top of it (signature unchanged).
  • Added a rand-extra reference test under test/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

  • ⚠️ Not built or run. The toolchain cannot be compiled in my environment (symlink-privilege and ANTLR/googletest-fetch blockers), so I could not execute spicetest.
  • Implemented against existing stdlib idioms (module globals, public free functions) and hand-verified the logic.
  • The rand-extra test uses range and seed-reproducibility assertions ending in printf("All assertions passed!"), so its cout.out is the meaningful success sentinel.
  • Please run spicetest --gtest_filter='*std*math*' to confirm before merge.

Follow-up / known limitations

  • randGaussian uses the Box-Muller transform; its reproducibility (not distribution shape) is what the test asserts.

🤖 Generated with Claude Code

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>
@marcauberer marcauberer requested review from a team as code owners June 15, 2026 15:48
@github-actions github-actions Bot added tests Contains changes to the test cases std Prs / issues regarding the standard lib labels Jun 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread std/math/fct.spice Outdated
Comment thread std/math/fct.spice Outdated
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>
@marcauberer marcauberer changed the title Extend std/math with classification, special functions and RNG Add std/math constants and a deterministic seedable RNG Jun 15, 2026
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@marcauberer marcauberer merged commit 4ab2beb into main Jun 15, 2026
8 checks passed
@marcauberer marcauberer deleted the std/extend-math-library branch June 15, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L std Prs / issues regarding the standard lib tests Contains changes to the test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant