mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8281183: RandomGenerator:NextDouble() default behavior partially fixed by JDK-8280950
Reviewed-by: jlaskey
This commit is contained in:
parent
42e272e181
commit
77b0240d44
2 changed files with 7 additions and 4 deletions
|
@ -677,7 +677,7 @@ public class RandomSupport {
|
||||||
double r = rng.nextDouble();
|
double r = rng.nextDouble();
|
||||||
r = r * bound;
|
r = r * bound;
|
||||||
if (r >= bound) // may need to correct a rounding problem
|
if (r >= bound) // may need to correct a rounding problem
|
||||||
r = Math.nextDown(r);
|
r = Math.nextDown(bound);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @summary Verify nextDouble stays within range
|
* @summary Verify nextDouble stays within range
|
||||||
* @bug 8280550 8280950
|
* @bug 8280550 8280950 8281183
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.SplittableRandom;
|
import java.util.SplittableRandom;
|
||||||
|
@ -79,9 +79,12 @@ public class RandomNextDoubleBoundary {
|
||||||
};
|
};
|
||||||
double value = rg.nextDouble(origin, bound);
|
double value = rg.nextDouble(origin, bound);
|
||||||
|
|
||||||
assertTrue(value >= origin);
|
if (bound > 0) {
|
||||||
|
value = rg.nextDouble(bound); // Equivalent to nextDouble(0.0, bound)
|
||||||
|
assertTrue(value >= 0.0);
|
||||||
assertTrue(value < bound);
|
assertTrue(value < bound);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertTrue(boolean condition) {
|
public static void assertTrue(boolean condition) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue