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

Incorrectly rounds huge float or double literal

XMLWordPrintable

    • sparc
    • solaris_2.5.1

      The following sample floating-point strings must be rounded to +Infinity
      when converted to binary representation. Instead, they are rounded
      to Float.MAX_VALUE and Double.MAX_VALUE respectively.

      class A {
          public static void main(String[] args) {
              System.out.println(3.4028235677973366E38f);
              System.out.println(Float.valueOf("3.4028235677973366E38"));
              System.out.println(1.79769313486231579979201547673599e308);
              System.out.println(Double.valueOf("1.79769313486231579979201547673599e30
      8"));
          }
      }

      Output:

      3.4028235E38
      3.4028235E38
      1.7976931348623157E308
      1.7976931348623157E308

      The original bug was filed against javac, which relies on the standard
      library to do the conversions. The original description follows:

      Name: dkC59003 Date: 07/06/98



      The following sample floating-point literals must be rounded to +Infinity
      when converted to binary representation, and compile-time error must
      be detected by javac. Nevetherless, javac (JDK 1.2b4K) rounds these
      constants to Float.MAX_VALUE and Double.MAX_VALUE respectively.

      ------------------------------------------------------------------

      class HugeFPLiteral {

          HugeFPLiteral (float value) {
      // The following value equals to:
      //
      // Float.MAX_VALUE + set_25th_bit_in_mantissa
      //
      // This value must be rounded to +Infinity according to
      // rounding-to-nearest rule, IEEE-754, section 4.3.

      float too_huge = 3.4028235677973366E38f; // must imply compiler error
          };

          HugeFPLiteral (double value) {
      // The following value equals to:
      //
      // Double.MAX_VALUE + set_53th_bit_in_mantissa
      //
      // This value must be rounded to +Infinity according to
      // rounding-to-nearest rule, IEEE-754, section 4.3.

      double too_huge = 1.79769313486231579979201547673599e308;
          };

      }

      ------------------------------------------------------------------

      This bug should be covered by the jmpp test:
          tests/lang/FP/fpl022/fpl02201m
      which is to be included into future versions of JCK.

      ======================================================================

            darcy Joe Darcy
            dkhukhrosunw Dmitry Khukhro (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: