Jump to content
Posted 14 September 2012 - 06:15 AM
Posted 14 September 2012 - 06:30 AM
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
Posted 14 September 2012 - 06:47 AM
Posted 14 September 2012 - 07:03 AM
I was wondering if using decimal here would be preferable?
Edited by laztrezort, 14 September 2012 - 07:04 AM.
Posted 14 September 2012 - 07:05 AM
The result is in fact zero... to seven digits of accuracy.
Now I've seen that a float has a 7point accuracy but as you can see I'm not using that, so what is the problem?
Posted 14 September 2012 - 07:15 AM
Posted 14 September 2012 - 07:18 AM
To summarize; seven digits of accuracy does not mean that any value with seven or less significant digits can be perfectly represented, it means that values are not exact but accurate to seven digits.
Posted 14 September 2012 - 02:58 PM
Posted 24 September 2012 - 03:43 PM
long double, in C and C++, may provide more precision than double, but it may also be the same (so you should check your implementation) (it will not have less precision than double, though). However, that doesn't get rid of the fact that you have to deal with floating point error, so the real answer is "understand floating point error and how to work with it," because float, double, and long double all suffer from floating point error. Just using a different data type doesn't really solve the problem. I'm surprised nobody's linked to this: What Every Computer Scientist Should Know About Floating-Point Arithmetic. It's rather long, but there's a lot of good stuff to learn in there, and you don't have to read it all to learn something useful.
so maybye use long double?