Difference between revisions of "Performance/Floating point"
DonStewart (talk  contribs) m (ffastmath is also useful) 
m (Performance/Floating Point moved to Performance/Floating point) 
(No difference)

Revision as of 21:55, 20 February 2006
Haskell Performance Resource
Constructs: Techniques: 
Don't use Float
Floats (probably 32bits) are almost always a bad idea, unless you Really Know What You Are Doing. Use Doubles. There's rarely a speed disadvantage—modern machines will use the same floatingpoint 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 will only take up less space than boxed Doubles if you are on a 32bit machine (on a 64bit machine, a Float still takes up 64 bits).
GHCspecific advice
On x86 (and other platforms with GHC prior to version 6.4.2), use the fexcessprecision flag to improve performance of floatingpoint intensive code (up to 2x speedups have been seen). This will keep more intermediates in registers instead of memory, at the expense of occasional differences in results due to unpredictable rounding. See the GHC documentation for more details. Switching on GCCs ffastmath and O3 can also help (use optcffastmath and optcO3).