What Every Programmer Should Know About Floating-Point Arithmetic
-brazil- writes "Every programmer forum gets a steady stream of novice questions about numbers not 'adding up.' Apart from repetitive explanations, SOP is to link to a paper by David Goldberg which, while very thorough, is not very accessible for novices. To alleviate this, I wrote The Floating-Point Guide, as a floating-point equivalent to Joel Spolsky's excellent introduction to Unicode. In doing so, I learned quite a few things about the intricacies of the IEEE 754 standard, and just how difficult it is to compare floating-point numbers using an epsilon. If you find any errors or omissions, you can suggest corrections."
Damn...Missed it! lol
Look, times are tough for programmers already. Knowing how to do things correctly - like proper floating point math - is one of the ways to separate the true CS professional from the wannabe new graduates. Articles like this just make everyone smarter, and make finding a job that much harder.
Really, the best answer is to store all numbers on the cloud, and just use a 256-bit GUID to look them up when needed.
It's missing the irritating cutesy "humor".
Warning: this article may contain humor, sarcasm, parody, and perhaps even irony. Read at your own risk.
Nobody would expect someone to write down 1/3
I use base 3, so 0.1 is a perfectly easy number to express in floating point.
The code on the site for
function nearlyEqual(a,b)
contains the line
if (a==0.0){
Clearly, this should be
if (nearlyEqual(a, 0.0)){
There. What could possibly go wrong now? :)
That would be because 0.1 + 02 is 2.1. :-)