3 ms·
I'm pretty sure Steve McConnel had a bit on this (adding the absolute magnitude "small" numbers up before the big ones - sorted) in order to avoid underflow and
by Roboprog 14y ago
I'm pretty sure Steve McConnel had a bit on this (adding the absolute magnitude "small" numbers up before the big ones - sorted) in order to avoid underflow and loss - in the book "Code Complete" back in the early 90s.
Obviously, it's a known old issue, since the IEEE folks point out that their standard produces an error (NaN) to indicate data loss if you add things with too small and too big a magnitude together. Not all floating point is IEEE, some implementations just give you their best estimate, throwing away the little bits.
And, please, DON'T use floating point to work with currency, ever. http://roboprogs.com/devel/2010.02.html http://roboprogs.com/devel/2010.02.html
- stephencanon 14y ago(1) NaN is not an error code. It is a value added to the system to make it closed under all the usual operations (thus eliminating the need for error codes). (2) Adding values of varying magnitude does not produce NaN results in IEEE-754 arithmetic. The only addition that produces a NaN is +Infinity + -Infinity, which have equal magnitude.
- Roboprog 14y agoWell, drat. I was under the impression from comments elsewhere in this thread that part of the (a?) standard was to track overflow/underflow. Go with what I know, then: add the small numbers first (sort the addends in increasing absolute magnitude)