with
printf("%lf\n",-1.0+0.9+0.1);
result is
0.000000
while with
cout<<-1.0+0.9+0.1;
result is
2.77556e-17
again, if i change
cout<<0.9+0.1+-1.0;
result is
0
why this different behavior simply inverting the sum?and why 2.77556e-17?is it the machine epsilon?and why I get it and not zero?
std::coutby default for floating point variables is similar to the%gflag rather than the%lfflag inprintf. In order to get the same behaviour, you have to passstd::fixedto the stream, e.g.: