-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
I am using JDK 8, but looking at the source code the problem appears to exist in the latest releases too.
A DESCRIPTION OF THE PROBLEM :
When the bounds of `nextDouble` are negative, they are sometimes not respected.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following Kotlin program:
```
fun main() {
val r = java.util.SplittableRandom(1L)
val o1 = 1.1
val o2 = o1.nextUp()
val origin = -o2
val bound = -o1
println(origin) // -1.1000000000000003
println(bound) // -1.1
for (i in 0 until 10) {
val x = r.nextDouble(origin, bound)
println(x) // -1.0999999999999999 (oops)
require(x == origin)
}
}
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should not fail requirement. Last println should always print -1.1000000000000003
ACTUAL -
Sometimes prints -1.0999999999999999 and fails the requirement
---------- BEGIN SOURCE ----------
Soo the Java source code in Steps to Reproduce
---------- END SOURCE ----------
FREQUENCY : always
I am using JDK 8, but looking at the source code the problem appears to exist in the latest releases too.
A DESCRIPTION OF THE PROBLEM :
When the bounds of `nextDouble` are negative, they are sometimes not respected.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following Kotlin program:
```
fun main() {
val r = java.util.SplittableRandom(1L)
val o1 = 1.1
val o2 = o1.nextUp()
val origin = -o2
val bound = -o1
println(origin) // -1.1000000000000003
println(bound) // -1.1
for (i in 0 until 10) {
val x = r.nextDouble(origin, bound)
println(x) // -1.0999999999999999 (oops)
require(x == origin)
}
}
```
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should not fail requirement. Last println should always print -1.1000000000000003
ACTUAL -
Sometimes prints -1.0999999999999999 and fails the requirement
---------- BEGIN SOURCE ----------
Soo the Java source code in Steps to Reproduce
---------- END SOURCE ----------
FREQUENCY : always
- duplicates
-
JDK-8280550 SplittableRandom#nextDouble(double,double) can return result >= bound
- Closed