by mustpax · 17y ago · 0 comments
The problem with floating point numbers is that most mathematical operations on them are approximations. People expect the same kind of correctness from floating point arithmetic that we've come to expect from integer arithmetic, when you really should be thinking in error bars.
I mean, just ask the average programmer to do currency math and I assure you they'll go straight for the `double`. Most of the time, not a catastrophic error, except for when it is.
For the curious, this is a long but very thorough overview of floating point arithmetic and it's quirks: http://docs.sun.com/source/806-3568/ncg_goldberg.html
For what little it's worth, I agree with Gowers, and have done since before I read that page, though I'd prefer to use binary rather than decimal.
In my defense, I wasn't trying to criticize the theoretical content of the article, which, in all honesty, is beyond my mathematical knowledge to criticize. The real number to "infinite" decimal conversion issue just reminded me of the age-old floating point number arithmetic problem, so I let out a little rant.
Also, I'm not a programmer, I'm a mathematician. Is the "right" way to do currency math do to integer arithmetic on prices expressed in cents (or, more generally, the smallest subdivision of the currency)?
Using floating point math for money is just asking for trouble.