Im using fmod() in one of my programs, and it is producing unexpected results, can anyone help me with this?
this is the code:
int main(int argc, char** argv)
{
double test = 0.756;
while (fmod(test, 1) != 0)
{
test = test * 10;
std::cout << test << " " << fmod(test, 1) << std::endl;
}
std::cout << "Final Product: " << test;
getchar();
return 0;
}
and this is the output:
7.56 0.56
75.6 0.6
756 1.13687e-13
7560 9.09495e-13
...
Final Product: 7.56e+15
Why does fmod(756, 1) == 1.13687e-13
? Shouldn't fmod(756, 1) == 0
?