Performance/Floating point

From HaskellWiki
< Performance
Revision as of 15:12, 10 January 2006 by Simonmar (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Don't use Float

Floats (probably 32-bits) are almost always a bad idea, anyway, unless you Really Know What You Are Doing. Use Doubles. There's rarely a speed disadvantage—modern machines will use the same floating-point unit for both. With Doubles, you are much less likely to hang yourself with numerical errors.

One time when Float might be a good idea is if you have a lot of them, say a giant array of Floats. An unboxed array of Float (see Performance:Arrays) takes up half the space in the heap compared to an unboxed array of Double. However, boxed Floats might take up less space than boxed Doubles if you are on a 32-bit machine (on a 64-bit machine, a Float still takes up 64 bits).