Roundoff

One of the guys at work stumbled across a instance of the strange ‘roundoff’ error that sometimes occurs in software. Building a game in Flash, he had his head in his hands several times trying to figure out why it couldn’t do some simple arithmetic. As it turned out, Flash was producing an error in rounding off a simple sum e.g. 1.01 - 1 was being evaluated to 0.0100000000000002.

Doesn’t sound like a big deal, but the mechanics of the game meant that the sum was being repeated several times. With rounding occurring at each step the difference in the displayed and true values became quite noticeable.

In our instance the effect was fairly trivial, but there have been some fairly prominent software bugs that have been attributed to this error. Most infamous of all seems to have been in the software used by the US Patriot missile defence system during the 1st Gulf War. An error in computation meant an Iraqi Scud missile breached the defence system and hit army barracks, killing 28 people.

Links :

Posted 4 years ago

I’m having the same problem in an online tax calculation program! It seems that 512.56 * 100 doesn’t equal 51256.
I have some examples and a function to parse financial user input on my website.

Johan van Mol · www · 3 years, 11 months ago

Commenting on this post has been disabled.

My name is Phil Lindsay, a web guy from Scotland, now living in Newcastle upon Tyne in England. I also run a web design company called Presence. You can email me at phil@xlab.co.uk, read more ramblings on my Twitter stream and view my photos on Flickr. You can grab the RSS feed for this weblog here.