Playing with some animation for a new BlackBerry product (see next post) and wondering about performance of double/float/Fixed32 arithmetic I came across this post on Blurry Words, which is exactly what I was looking for.
Basically performance depends on the type of arithmetical operation you’re doing (though double is always slowest, usually by a wide margin). For addition and subtraction, Fixed32 is faster, for multiplication and division float wins out. Some sample results:
|Variable Type||Add/Sub (ms)||Mult (ms)||Div (ms)|
The net.rim.device.api.math.Fixed32 class is interesting – I’ve mostly used it in scaling EncodedImages. It packs a fixed decimal representation of a number into a 32 bit int datatype, using the leftmost 16 bits for the whole part, and the rightmost 16 bits for the fractional part. This has the result that the normal + and – operators work as expected, but multiply and divide are handled through special functions.
Though I’ve gotta disagree with the poster’s conclusions – Fixed32 is not strictly legacy, it’s only been available since OS 4.0, at which time float and double were available on BlackBerry.
There’s a lot more interesting discussion and more results for different devices just in this post, so I encourage to read the original!