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

Multiplication of any integer multiple of 5 with 0.000001 faulty!

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs
    • generic
    • generic



      Name: yyT116575 Date: 03/05/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


      Test the following source code:

      //----------------------------
      import java.lang.*;

      public class test2 {

        public static void main(String[] argv) {
          double counter;
          counter=Double.parseDouble(argv[0]);
          double factor=0.000001;
          
          System.out.println("test:"+Double.toString(counter*factor));
          
        }
      }
      // --------------------------------------


      after compiling call this program with 'java test2 5'
      the result should be: 5.0E-6 but it isn't. it is: 4.9999999999999996E-6.
      Something like this happens for all values which are integer multiples of 5.
       5-> 4.9999999999999996E-6
      10-> 9.9999999999999998E-6
      15-> 1.4444444444444449E-5
      20-> 1.9999999999999998E-5
      ...

      Calling the program with other integers, for example 4, produces the expected
      output: '4.0E-6'.
      The problem stays the same with negative values. With zero (0) everything is
      okay.

      I tested the program on a Compaq Armada 1592DT running RedHat Linux 6.2 and on a
      Windows 98 Pentium III 650 MHz with JRE1.3 running on both systems.
      (Review ID: 118143)
      ======================================================================

            darcy Joe Darcy
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: