c++ (about double and float)
Some asked me a question about a surpassingly bug in vc++. The original code looked like this:
double index;
for(index=0.0;index<1.0;index+=0.1)
cout<<(int)(index*10.0)<<endl;
//should print 0 1 2 3 4 5 6 7 8 9, but prints 0 1 2 3 4 5 6 7 7 9 9
I changed double to a float:
float index;
for(index=0.0;index<1.0;index+=0.1)
cout<<(int)(index*10.0)<<endl;
return 0;
and all went well, I don’t remember the exact reason ( the way float and double resides in memory + conversion issues to an int) but it's obviously not a bug.