Difference between revisions of "Performance/Floating point"
m (+infobox) |
m |
||
Line 4: | Line 4: | ||
<tt>Floats</tt> (probably 32-bits) are almost always a bad idea, anyway, unless you Really Know What You Are Doing. Use <tt>Double</tt>s. There's rarely a speed disadvantage—modern machines will use the same floating-point unit for both. With <tt>Double</tt>s, you are much less likely to hang yourself with numerical errors. |
<tt>Floats</tt> (probably 32-bits) are almost always a bad idea, anyway, unless you Really Know What You Are Doing. Use <tt>Double</tt>s. There's rarely a speed disadvantage—modern machines will use the same floating-point unit for both. With <tt>Double</tt>s, you are much less likely to hang yourself with numerical errors. |
||
− | One time when <tt>Float</tt> might be a good idea is if you have a ''lot'' of them, say a giant array of <tt>Float</tt>s. An unboxed array of <tt>Float</tt> (see [[Performance:Arrays]]) takes up half the space in the heap compared to an unboxed array of <tt>Double</tt>. However, boxed <tt>Float</tt>s |
+ | One time when <tt>Float</tt> might be a good idea is if you have a ''lot'' of them, say a giant array of <tt>Float</tt>s. An unboxed array of <tt>Float</tt> (see [[Performance:Arrays]]) takes up half the space in the heap compared to an unboxed array of <tt>Double</tt>. However, boxed <tt>Float</tt>s will only take up less space than boxed <tt>Double</tt>s if you are on a 32-bit machine (on a 64-bit machine, a <tt>Float</tt> still takes up 64 bits). |
Revision as of 10:31, 16 January 2006
Haskell Performance Resource
Constructs: Techniques: |
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 will only 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).