Apr 14, 2016 at 6:47am UTC
Here is a MCVE of a ">" operator behavior I do not really understand, although I suspect it has something to do with number precision:
#include <iostream>
int main(){
double var1, var2;
var1 = 1.91;
var2 = 1.31;
for(int ii=0; ii<100; ++ii){
if(var2 > var1){
std::cout << "var2 = " << var2 << " is greater than var1 = " << var1 << std::endl;
return 0;
}
var2 += 0.01;
}
return 0;
}
This code returns:
var2 = 1.91 is greater than var1 = 1.91
Why is that? Are the numbers being printed not the same as the ones the code is using? This has probably been answered somewhere else before but finding it proved difficult
Apr 14, 2016 at 8:11am UTC
Thanks for the fast answer.