Repository navigation
Keep NextDoubleExclusive strictly below 1 at the top draw [patch] - #92
Merged
Merged
Conversation
The 53-bit draw plus half a step is not representable for the largest draw: (2^53 - 1) + 0.5 is a tie that rounds to even, 2^53, so the method returned exactly 1.0 and Normal/LogNormal Sample returned +Infinity. Draw 52 bits instead, so every half-step sum is exact and the result lies in [2^-53, 1 - 2^-53]. Fixes #60 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ABXREnMPNwAYQMdr4STcfE
|
This was referenced Oct 7, 2026
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.



Fixes #60
What was wrong
NextDoubleExclusive()scaled(NextUInt64() >> 11) + 0.5by 2^-53. For the largest 53-bit draw,(2^53 - 1) + 0.5is a tie between2^53 - 1and2^53, and round-half-to-even picks2^53. The method returned exactly1.0, soNormal(0,1).SampleandLogNormal.Samplereturned+Infinity.Change
RandomHelpers.OpenUnitScale). Every half-step sum is now exact, so results lie in[2^-53, 1 - 2^-53].Tests
NextDoubleExclusive_Excludes_Both_Ends_At_The_Extreme_Drawsuses a constant-word stub provider forulong.MaxValueand0. It asserts0 < u < 1and that Normal and LogNormal samples are finite.ulong.MaxValuecase fails withNextDoubleExclusive returned 1. With the fix, it passes.Related: #61 covers a separate boundary bug in
NextDouble(min, max)and is left to its own PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01ABXREnMPNwAYQMdr4STcfE
Generated by Claude Code