"Luc Le Blanc" <[EMAIL PROTECTED]> a écrit dans le message de news: 
[EMAIL PROTECTED]
> Maybe someone knows (perhaps Ben ;) about the optimization of float 
> operations under CodeWarrior 9.3:
>
> Is dividing by 100.0 as fast (or slow) as multiplying by 0.01 ?
>
> Is multiplying by 1.0 costlier than checking for == 1.0 (and then not 
> multiplying) ?
>
> I am trying to speed up a graph draw procedure that involves a lot of 
> computations.
>
>
> -- 
> Luc Le Blanc
>

Luc,

In general, when you can afford the range limitation, its mutch faster to 
use offsetted (or  scalled) integers.
Its an old trick that I use to use when I was designing and programing small 
devices based on 8 bits microcontrolers.

If you want 2 digits precision, you can multiply your values by 1000.
So 0.01 is 10 in your internal variables.
You adjust you scalling vs the number of digits you want and the max 
possible value.
If you want a bigger span, you can use "long long" values but you will need 
to benchmark to see if is faster than floats( I'm betting it is)

Int32 lngX, lngY,lngResult;

lngX=54321;     // 54.321 * 1000
lngY=12345;        // 12.354 *1000

lngResult=lngX / lngY;    // 4400 = 4.400 * 1000

-- 
Regis St-Gelais
www.laubrass.com



-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to