Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8281183: RandomGenerator:NextDouble() default behavior partially fixe…
…d by JDK-8280950

Reviewed-by: jlaskey
  • Loading branch information
jddarcy committed Feb 6, 2022
1 parent 42e272e commit 77b0240
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Expand Up @@ -677,7 +677,7 @@ public static double boundedNextDouble(RandomGenerator rng, double bound) {
double r = rng.nextDouble();
r = r * bound;
if (r >= bound) // may need to correct a rounding problem
r = Math.nextDown(r);
r = Math.nextDown(bound);
return r;
}

Expand Down
9 changes: 6 additions & 3 deletions test/jdk/java/util/Random/RandomNextDoubleBoundary.java
Expand Up @@ -24,7 +24,7 @@
/*
* @test
* @summary Verify nextDouble stays within range
* @bug 8280550 8280950
* @bug 8280550 8280950 8281183
*/

import java.util.SplittableRandom;
Expand Down Expand Up @@ -79,8 +79,11 @@ public long nextLong() {
};
double value = rg.nextDouble(origin, bound);

assertTrue(value >= origin);
assertTrue(value < bound);
if (bound > 0) {
value = rg.nextDouble(bound); // Equivalent to nextDouble(0.0, bound)
assertTrue(value >= 0.0);
assertTrue(value < bound);
}
}

public static void assertTrue(boolean condition) {
Expand Down

3 comments on commit 77b0240

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@jddarcy
Copy link
Member Author

@jddarcy jddarcy commented on 77b0240 Feb 9, 2022

Choose a reason for hiding this comment

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

/backport jdk18u

@openjdk
Copy link

@openjdk openjdk bot commented on 77b0240 Feb 9, 2022

Choose a reason for hiding this comment

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

@jddarcy the backport was successfully created on the branch jddarcy-backport-77b0240d in my personal fork of openjdk/jdk18u. To create a pull request with this backport targeting openjdk/jdk18u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 77b0240d from the openjdk/jdk repository.

The commit being backported was authored by Joe Darcy on 6 Feb 2022 and was reviewed by Jim Laskey.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk18u:

$ git fetch https://github.com/openjdk-bots/jdk18u jddarcy-backport-77b0240d:jddarcy-backport-77b0240d
$ git checkout jddarcy-backport-77b0240d
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk18u jddarcy-backport-77b0240d

Please sign in to comment.