I have a simple C++ program compiled using gcc 4.2.4 on 32-bit Ubuntu 8.04. It has a for-loop in which a double variable is incremented from zero t
for
double
Generally, when you compare doubles, simple comparison is not good enough, and you should compare them "up to a precision". i.e. :
if ( fabs(double1-double2) < 0.0000001 ) { do-something }
The problem occurs due to the representation of double variables.