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

float rounding error in JDK1.1 and JDK 1.1.1

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • None
    • 1.1, 1.1.1
    • core-libs
    • sparc
    • solaris_2.5.1

      The following example gives a float rounding error on 1.1 (and 1.1.1B)
      but not on previous versions.

      It IS only a rounding error, but Licensee (IBM) is concerned
      that anything as fundamental as arithmetic should apparently have
      regressed.

      import java.io.*;
      import java.lang.*;

      public class IOTest
      {
          public static void main (String[] args)
          {
              if (args.length == 0)
              {
                  System.out.println ("There is [" +
                      args.length + "] arguments:");
                  System.exit (1);
              }

              for (int i= 0; i < args.length; i++)
              {
                  System.out.println ("Input String: <" +
                      args[i] + ">");
              }

              float output = new Float(args[0]).floatValue();
              System.out.println ("Before addition: <" + output + ">");
              output += 1.011;
              System.out.println ("After adding 1.011: <" + output + ">");
          }
      }

      Results from JDK1.0.2:

      java IOTest 445.348
      Input String: <445.348>
      Before addition: <445.348>
      After adding 1.011: <446.359>

      Results from JDK1.1:

      java IOTest 445.348
      Input String: <445.348>
      Before addition: <445.348>
      After adding 1.011: <446.35898>

            mr Mark Reinhold
            rschiavisunw Richard Schiavi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: