Repository navigation
Conversation
…ider than Long.MAX_VALUE Signed-off-by: Sebastian Turner <sebastiant3484@gmail.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 changes are proposed in this pull request, and why are they necessary?
IntegerDomain.sampleFromIntervalhas an overflow branch for intervals whose width exceedsLong.MAX_VALUE, but it still computesinterval.max - interval.minas along. The difference wraps around, so:IntegerDomain.of(Long.MIN_VALUE, 5).sample(n)returns large positive values that are not in the domain.IntegerDomain.all().sample(n)always returnsLong.MIN_VALUE.This change computes the width in
double, samples indoublespace, and clamps the result to[min, max]to absorb rounding at the edges.How was this patch tested?
Added
IntegerDomainTest.testSampleIntervalWiderThanLongMaxValue, which samples[Long.MIN_VALUE, 5],[-5, Long.MAX_VALUE]andIntegerDomain.all(), and checks that every sample is contained in the domain and that the samples are not all the same value. It fails on master (IntegerDomain[[-9223372036854775808, 5]] sampled 8059531451386583040) and passes with the fix; I ran it repeatedly to make sure it is not flaky../gradlew :coral-data-generation:spotlessCheck :coral-data-generation:testpasses.Fixes #628