Floating-point errors, explained

3 Min Read

Back in March, we looked at the reasons behind apparent arithmetic “mistakes” that can occur in software programs like R that use floating-point arithmetic, like this:    

> 1.0 – 0.9 – 0.1
[1] -2.775558e-17

Of course, the answer should be zero, but it’s not, not exactly anyway. That example (which I wish I’d thought of myself at the time) comes from an well-written and informative article published in PC Plus and available online at techradar.com. In simple, non-technical terms, it explains why such floating-point errors occur. It also gives some examples of the consequences of not anticipating such errors, like the Ariane 5 rocket that self-destructed 5 seconds after launch, or the Patriot missile that failed to target an Iraqi Scud missile that killed 28 people. 

These horror stories explain why good programmers should always be aware of the pitfalls of using floating-point arithmetic and to program defensively to avoid them. (I gave some tips for R in that article from March.) It’s a great article to send next time someone asks you why their code isn’t giving a exactly the right result when they think it should.

TechRadar.com: Why computers



Back in March, we looked at the reasons behind apparent arithmetic “mistakes” that can occur in software programs like R that use floating-point arithmetic, like this:    

> 1.0 – 0.9 – 0.1
[1] -2.775558e-17

Of course, the answer should be zero, but it’s not, not exactly anyway. That example (which I wish I’d thought of myself at the time) comes from an well-written and informative article published in PC Plus and available online at techradar.com. In simple, non-technical terms, it explains why such floating-point errors occur. It also gives some examples of the consequences of not anticipating such errors, like the Ariane 5 rocket that self-destructed 5 seconds after launch, or the Patriot missile that failed to target an Iraqi Scud missile that killed 28 people. 

These horror stories explain why good programmers should always be aware of the pitfalls of using floating-point arithmetic and to program defensively to avoid them. (I gave some tips for R in that article from March.) It’s a great article to send next time someone asks you why their code isn’t giving a exactly the right result when they think it should.

TechRadar.com: Why computers suck at maths

Link to original post

Share This Article
Exit mobile version