
What Every Computer Scientist Should Know About Floating-Point Arithmetic - kqr2
http://docs.sun.com/source/806-3568/ncg_goldberg.html
======
RiderOfGiraffes
An old friend that we see time and time again. Here are a few, although there
isn't much discussion:

<http://news.ycombinator.com/item?id=1937182>

<http://news.ycombinator.com/item?id=1746797>

<http://news.ycombinator.com/item?id=687604>

<http://news.ycombinator.com/item?id=453396>

~~~
T-zex
Repetitio Est Mater Studiorum

------
bobds
Instead of the same old paper again, how about a comparison of the ways
current language implementations handle floating point numbers?

~~~
dfox
There is no meaningful difference, because it is dependent on how CPUs handle
FP arithmetic. And only significant change in that from time when this paper
was published is that IBM got their decimal FP formats as optional part into
standard that everyone uses for FP arithmetics.

~~~
ced
Technically, that's true, but the more interesting question is "How do
languages handle _non-integers_?"

Quite a few languages (like Lisp) have a rational data type, such that 1/3 +
1/4 is done exactly. Others have a decimal data type, whose main purpose is
for calculations involving money. 0.1 + 0.2 = 0.3

And finally, I'm no expert on Mathematica, but IIRC it computes error bounds
on your results, and it only displays decimal digits if they are within those
bounds. It's the proper way of doing things, and again, 0.1 + 0.2 = 0.3

------
jwr
TL;DR summary in the spirit of times: when doing floating-point math, expect
your results to float. There be dragons. Big ones.

~~~
mgedmin
Actually, my takeaway from this paper was exactly the opposite: if you
understand how floats work, you can trust the results of floating-point
calculation.

------
brazzy
And for those without a math or CS degree: <http://floating-point-gui.de/>

------
aidenn0
Friends don't let friends use floating point numbers.

Computers are so darn fast today that there is no excuse for not using an
arbitrary precision library. Floating point should be thought of as an
optimization, not as a default.

Unless you are writing DSP code (in which case this article should be nothing
new), don't use floating point!

------
wladimir
Great. This isn't just useful for computer scientists, though. Also for other
sciences that do computer simulations of any kind. And hopefully programmers
will read it too and stop making awful mistakes such as using floating point
values for money amounts.

------
kondro
I'm glad I work in a world where the performance overhead of decimal (both SQL
and Ruby's BigDecimal) isn't too high.

I still remember when every Rails-based example with an invoice in it stored
dollar amounts in the DB as floats. Ahh bless.

------
nagnatron
I remember seeing this article in the lecture notes of my Numerical Analysis
class. Very cool read.

