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

Fix two typos in the spec of j.u.random.RandomGenerator

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • behavioral
    • minimal
    • While the spec is incorrect, the implementation is correct. There is no behavioral change.
    • Java API
    • SE

      Problem

      The spec of the interface java.util.random.RandomGenerator states: "In the case of float and double values, first a value is always chosen uniformly from the set of 2^w values between 0.0 (inclusive) and 1.0 (exclusive), where w is 23 for float values and 52 for double values, ..."

      This is incorrect. Instead, it should state "w is 24 for float values and 53 for double values" or perhaps better "w is Float.PRECISION for float values and Double.PRECISION for double values, ..."

      In addition, there are explicit literals 24 and 53 in the @implSpec of nextFloat() and nextDouble(), resp. They should be replaced by *.PRECISION as well.

      Solution

      As illustrated above.

      Specification

      interface spec

      - * where <i>w</i> is 23 for {@code float} values and 52 for {@code double}
      + * where <i>w</i> is {@link Float#PRECISION} for {@code float} values
      + * and {@link Double#PRECISION} for {@code double}

      nextFloat() spec

      -     * @implSpec The default implementation uses the 24 high-order bits from a call to
      -     * {@link RandomGenerator#nextInt() nextInt}().
      +     * @implSpec The default implementation uses the {@link Float#PRECISION}
      +     * high-order bits from a call to {@link RandomGenerator#nextInt() nextInt}().

      nextDouble() spec

      -     * @implSpec The default implementation uses the 53 high-order bits from a call to
      -     * {@link RandomGenerator#nextLong nextLong}().
      +     * @implSpec The default implementation uses the {@link Double#PRECISION}
      +     * high-order bits from a call to {@link RandomGenerator#nextLong nextLong}().

            rgiulietti Raffaello Giulietti
            rgiulietti Raffaello Giulietti
            Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: