Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real life example fo Floating Point error

Is there any examples of a company that was burned by floating point data that caused a rounding issue? We're implementing a new system and all the monetary values are stored in floats. I think if i can show actual examples of why this has failed it'll have more weight than the theory of why the values can't be stored properly.

like image 654
Rob Avatar asked Apr 28 '10 20:04

Rob


1 Answers

These examples are from the embedded world (Ariane 5, Patriot) but are not floating-point rounding errors stricto sensu. The Ariane 5 bug is a bug in a conversion. The Patriot bug was introduced during adaptations of the software. It involves computations in different precisions with an inherently unrepresentable constant (which happens to be the innocuous-looking 0.10).

There are two problems I foresee with binary floats for monetary values:

  • decimal values as common as 0.10 cannot be represented exactly.

  • If the precision is too small, what could have been a clean overflow raising an exception becomes a hard-to-track loss of precision.

Note that base-10 floating-point formats have been standardized precisely for monetary values: some currencies are worth 1/1000000 of a dollar, are never exchanged in less than thousands, and the maximum amount you may want to be able to represent is proportionally big, so a scalable representation makes sense. The intent is that the mantissa is large enough for the largest sums with the official resolution.

like image 146
Pascal Cuoq Avatar answered Sep 28 '22 02:09

Pascal Cuoq