Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8282082

Bounded double values do not obey negative bounds

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      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


      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: