PRC Recording Studio PRC Recording Studio PRC Recording Studio
Genealogy of my kin

Floating Point numbers considered harmful

Arrrggghhh, there are many days when I wish that computers did not have floating point number representations, and that computer tools did not make it so easy for novice users to use floating point.

Rule Number 1:

Using Floating point numbers for accounting is a sin.

Observation Number 1:

Too many tools and languages, like Microsoft Excel and Perl, default to using, or sometimes only use, floating point. Do not use them for accounting.

       

Floating point precision

Floating point numbers have inherant characteristics. Some are good, like their large range, and some are not so good, like their inability to precisely represent many useful values. This is a feature. Get used to it.

The easy example is to try to represent the rational number 0.10 as a 32-bit floating point. It is always represented internally as 0.09999999, which is usually good enough. After all, it rounds to 0.10 reliably. Or use double precision floating point (64-bit) and you will find that it is represented as 0.0999999999999, which is again pretty close.

Classical science and engineering definitions of Precision and Accuracy.

Science and enginnering have well established definitions for "accuracy" and "precision" of measurements. They are not symonyms!

Accuracy is the deviation of a measurement (although usually the mean of a set of measurements) from the "true" value being measured.

Precision is the measure of the agreement of measured values with each others, usually specified as the standard deviation.

Floating point number precision is not a measurement problem, 0.10 is always represented by the same number, one that is always a little off from the "true" value.

Copyright © 2004-2005 Farrell and Associates.