RFR: 8326227: Rounding error that may distort computeNextGaussian results [v3]

Jaikiran Pai jpai at openjdk.org
Wed Jun 12 09:38:22 UTC 2024


On Wed, 21 Feb 2024 02:18:08 GMT, Chris Hennick <duke at openjdk.org> wrote:

>> This provides a slightly more accurate bounding limit for `computeNextExponentialSoftCapped` when calling it from `computeNextGaussian`. This could cause the `while (computeNextExponentialSoftCapped(rng, limit) < limit)` check in `computeNextGaussian` on line 1402 to always be true, making the `nextGaussian` runtime unbounded in the worst case; but more likely, it would give a result that was truncated too close to zero.
>> 
>> This change is being tested prior to submission to OpenJDK by https://github.com/openjdk/jdk/pull/17703/commits/b8be051cbf40a6a05fafc6a2c76942e9e0b11fdf.
>
> Chris Hennick has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Bug fix: add-exports was for wrong package

test/jdk/jdk/internal/util/random/RandomSupportTest.java line 32:

> 30:         for (double max = 1.0; max < 10.0; max++) {
> 31:             WorstCaseRandomGenerator rng = new WorstCaseRandomGenerator();
> 32:             assertTrue(RandomSupport.computeNextExponentialSoftCapped(rng, max) >= max);

Would you mind changing this to something like:

double val = RandomSupport.computeNextExponentialSoftCapped(rng, max);
assertTrue(val >= max, val + " isn't >= " + max);


That way if this test fails for any reason, then we get the necessary details on what the computed value is.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17703#discussion_r1636139162


More information about the core-libs-dev mailing list