Careful with the omissions...
Posted May 1, 2006 23:59 UTC (Mon) by Stavros
In reply to: a few notable omissions...
Parent article: Portability and Pitfalls of C-Types (developerWorks)
[...] unless you really know what you are doing, use double precision!
I disagree. In particular for storage, whether in memory or on disk, the careful choice of storage type for floats is a valuable memory jog telling you to pay attention to the precision of your calculations. An apparent loss of precision is rarely due to insufficient size of the storage or processing type but rather due to a poor choice of calculational method.
The danger in simply taking the double-precision-short-cut is that you can fool yourself into thinking you have much more precision than you really do ("Look at all those digits!"). I have been working in scientific computing for many, many years and even there, where everyone should know better, it is surprising how often people calculate a small quantity by subtracting a large quantity from another large quantity and using double (or even quadruple) precision in the mistaken belief that the problem is solved. Then they are shocked when the input quantization wreaks havoc with the results.
For those who want to know more, read "What Every Computer Scientist Should Know About Floating Point Arithmetic" (David Goldberg, 1991). The issues are also discussed in many books on numerical analysis, though often in less detail.
Numerical calculaton is rarely simple and rules of thumb like using doubles by default can be very dangerous. Kudos if you know this and are careful in your math, but I worry about leading less aware people astray.
to post comments)