Name: gm110360 Date: 06/18/2002
FULL PRODUCT VERSION :
C:\>java -version
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows NT Version 4.0
A DESCRIPTION OF THE PROBLEM :
double a = 12.10d;
double b = 10.11d;
double c = a-b ;
"The value of c is 1.9900000000000002" i think it should be
1.99 (by basic maths)
So the statement 1.99 == c gives false
as c is having the value 1.9900000000000002
the logical answer to the output c + b is
12.1000000000000002
but the actule answer is 12.1 ????
which is equal to a
The above thing Violating the basic maths...
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the code once
EXPECTED VERSUS ACTUAL BEHAVIOR :
double a = 12.10d;
double b = 10.11d;
double c = a-b ;
value of c should be 1.99
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class sh
{
public static void main(String w[])
{
try
{
double a = 12.10d;
double b = 10.11d;
double c = a-b ; // 1.99
//Point 1
System.out.println(c == 1.99d); /* output false ,
Logically it should be true */
//Point 2
System.out.println(" value of c -> "+c); /* out put is
1.9900000000000002 so it is not 1.99 !!!!!! */
//Point 3
System.out.println( (c + b)); // ouput 12.1 ??????
//Point 4
System.out.println( (c + b)== a); //true !!!
}catch(Exception e)
{
System.out.println(e);
}
}
}
---------- END SOURCE ----------
(Review ID: 153759)
======================================================================
- relates to
-
JDK-4421899 Multiplication of any integer multiple of 5 with 0.000001 faulty!
-
- Closed
-
-
JDK-4430070 double and float not calculating correctly
-
- Closed
-
-
JDK-4497156 double (primitive) arithmetic precision error
-
- Closed
-