Floating-point errors, explained

November 5, 2009
49 Views

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

You may be interested

How SAP Hana is Driving Big Data Startups
Big Data
298 shares3,060 views
Big Data
298 shares3,060 views

How SAP Hana is Driving Big Data Startups

Ryan Kh - July 20, 2017

The first version of SAP Hana was released in 2010, before Hadoop and other big data extraction tools were introduced.…

Data Erasing Software vs Physical Destruction: Sustainable Way of Data Deletion
Data Management
60 views
Data Management
60 views

Data Erasing Software vs Physical Destruction: Sustainable Way of Data Deletion

Manish Bhickta - July 20, 2017

Physical Data destruction techniques are efficient enough to destroy data, but they can never be considered eco-friendly. On the other…

10 Simple Rules for Creating a Good Data Management Plan
Data Management
69 shares664 views
Data Management
69 shares664 views

10 Simple Rules for Creating a Good Data Management Plan

GloriaKopp - July 20, 2017

Part of business planning is arranging how data will be used in the development of a project. This is why…