(C++) I know doubles have tiny accuracy problems but mine seem unreasonable
When I cout<<10.9 + 10.0; I get 20.911. Seriously? Thats horrible accuracy. And when I do the addition in my real code it comes out as 20.913. I was expecting errors to be much much smaller than that. Is there some kind of compiler flag I can set to make it more accurate?
There is no std::endl at the end. My guess is that it outputs 20.9 (which is roughly correct *) and that the 11 is outputted later on.
Edit: * meaning, that floats/doubles can not represent 10.9 or 20.9 in the same way, that the decimal system can not represent 1/3
Edit: * meaning, that floats/doubles can not represent 10.9 or 20.9 in the same way, that the decimal system can not represent 1/3
When I cout<<10.9 + 10.0; I get 20.911. Seriously? Thats horrible accuracy. And when I do the addition in my real code it comes out as 20.913. I was expecting errors to be much much smaller than that. Is there some kind of compiler flag I can set to make it more accurate?
i forgot a lot about that stuff but maybe this page will help
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
After trying it out myself I got 20.9, so I think, like Ohforf sake, that you append the 11 or 13 later on.
Look at your code, where is the next cout? Is that one the 11-printing culprit? Or try ending your cout with endl, normally you should get the following output:
20.9
11
Look at your code, where is the next cout? Is that one the 11-printing culprit? Or try ending your cout with endl, normally you should get the following output:
20.9
11
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement