3 ms·
On a somewhat related note: as computer scientists, we're usually dealing with discrete data, so correctness comes naturally to us with discrete problems. The
by mustpax 17y ago
On a somewhat related note: as computer scientists, we're usually dealing with discrete data, so correctness comes naturally to us with discrete problems.
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 http://docs.sun.com/source/806-3568/ncg_goldberg.html
- gjm11 17y agoThat's all very well (and Goldberg's paper is excellent); but it has nothing whatever to do with the linked page, which is by Fields medallist Tim Gowers, arguing that in pure mathematics "infinite decimals" is as good a way to construct the real numbers as "Cauchy sequences" or "Dedekind cuts". 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.
- mustpax 17y agoThanks for pointing that out, I stand corrected. 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.
- 321abc 17y agoAlso see: http://speleotrove.com/decimal http://speleotrove.com/decimal
- madcaptenor 17y agoNot just computer scientists. I think normal people are used to dealing with discrete data. Ask a person on the street to name some numbers and they'll almost certainly give you integers. 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)?
- bena 17y agoAn integer expressing dollars, cents, or hundredths of a cent depending on the level of precision you need is the usual best practice. Using floating point math for money is just asking for trouble.