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

fp.bugs 4009 addition of doubles produces incorrect behavior

XMLWordPrintable

    • sparc
    • solaris_2.5

      Java JDK 1.0 Bug Report

      Problem: addition of doubles produces incorrect behavior

      Platforms: Linux 1.2.??, SPARCStation 5/SunOS 5.3

      Reproducing the problem: Compile and run the following java program:
      ---------------
      class TestApp {
      public static void main(String args[]) {
      double a = 1999.99, b = 299.99, c = 299.99, d = 399.99,
      e = 699.99, f = 59.95;
      double total = a + b + c + d + e + f;
      double reference = 3759.9; // this is what the total should be
      System.out.println("Total, converted to String: "
                             + String.valueOf(total));
      System.out.println("Total, *100.0, cast to long: "
      + String.valueOf((long) (total * 100.0)));
      System.out.println("Total compared to (double) 3759.9: "
      + (total == reference));
      }
      }
      ---------------

      Output (on Linux, SunOS):
      ---------------
      Total, converted to String: 3759.9
      Total, *100.0, cast to long: 375989
      Total compared to (double) 3759.9: false
      ---------------




      Brandon Volbright, Art Technology Group
      ###@###.###
       

            egilbertsunw Eric Gilbertson (Inactive)
            bhagen Benjamin Hagen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: