Integer vs. FP

Rob Lewis rob at whidbey.com
Thu Jun 26 12:12:42 PDT 2003


On Thursday, Jun 26, 2003, at 09:23 US/Pacific, Macintosh Digital Video 
List wrote:

> I wish I could find someone who could. My impression was that integer
> used to be much more important, but that it was a side effect of
> processors simply being much faster at integer math than floating
> point. That means many developers coerced their floating point data
> into integer values to improve performance.

This is exactly right. Floating point traditionally has been MUCH 
slower than integer.

> The simplest example would
> be a checkbook program that represents everything internally in cents
> (integer) and only converts to dollars and cents (floating point) for
> display purposes.

Actually, a lot of financial math is done in BCD (binary-coded decimal, 
where 4 bits are used to represent a digit from 0 to 9). This makes the 
pennies come out right, and is how typical pocket calculators work too. 
But then, most financial software isn't really math-intensive, so it's 
not a big deal what you use.
>
> Since floating point speed has caught up and sometimes outstripped
> integer speed, those kinds of hacks are no longer necessary. Which
> really leaves me wondering what the relative importance between fp and
> int really is today.

In a nutshell: use FP when you need to represent a very wide range of 
data, from very small to very large numbers. Use integer when you need 
exact-to-the-nit results and the data is of limited range and you don't 
mind handling any necessary scaling yourself.

It is worth noting that Apple has adopted FP as the default 
representation for audio data in OS X's Core Audio system. This 
essentially eliminates any worries about scaling the data, and 
overflowing or underflowing registers. It wouldn't have been possible 
in the days of slow FP units. Present-day pro audio samples use 24 
(integer) bits. Apple's FP format keeps all 24, and adds an 8-bit 
exponent. So really, nothing is lost and a lot is gained.

> Also, consider this. The G5 has two integer
> execution units and two floating point units. If integer math was so
> overwhelmingly important, why wouldn't they have 3 integer units and
> one floating point?

I think precisely because now that FP is as fast as integer, it will 
find a lot more uses.



More information about the MacDV mailing list