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)
======================================================================
- relates to
-
JDK-4704007 (c = a - b ) or (a = c + b) maths equation false with double/float
-
- Closed
-
-
JDK-4950948 loop statements with double-type index, can ends at incorrect index.
-
- Closed
-