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

Add a PRECISION public static field to j.l.Float and j.l.Double

    XMLWordPrintable

Details

    • CSR
    • Status: Closed
    • P4
    • Resolution: Approved
    • 19
    • core-libs
    • None
    • minimal
    • There's no compatibility risk, as the proposal adds new static fields.
    • Java API
    • SE

    Description

      Summary

      Add a PRECISION public static final field to java.lang.Float and java.lang.Double

      Problem

      The precision of float and double values, as defined by IEEE 754, is not easily derivable from the constants in the java.lang.Float resp. java.lang.Double classes. These values (24 resp. 53) are used in some places in the OpenJDK code base, where they appear as literals or even as derived literals, like 23 and 52. Hence, usages of these values are harder to find than necessary.

      Solution

      It is proposed to add a PRECISION public static field to these classes. The values for MAX_EXPONENT and MIN_EXPONENT are then derived from static expressions at compile time, rather than being defined as literals.

      Later enhancements could then replace the literals in the code base with the field names.

      Specification

      java.lang.Float

          /**
           * The number of bits in the significand of a {@code float} value.
           * This is the parameter N in section {@jls 4.2.3} of
           * <cite>The Java Language Specification</cite>.
           *
           * @since 19
           */
          public static final int PRECISION = 24;

      java.lang.Double

      /**
       * The number of bits in the significand of a {@code double} value.
       * This is the parameter N in section {@jls 4.2.3} of
       * <cite>The Java Language Specification</cite>.
       *
       * @since 19
       */
      public static final int PRECISION = 53;

      Attachments

        Issue Links

          Activity

            People

              rgiulietti Raffaello Giulietti
              rgiulietti Raffaello Giulietti
              Joe Darcy
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: