no, sorry but division and multiplication are not so simple. the
division you gave will result in the integer value 4, not more. to get
it right you'd need to multiply by the scale factor before the
division.

On 6/6/06, Regis St-Gelais <[EMAIL PROTECTED]> wrote:
"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/



--
Best Regards, Dmitry Grinberg
Software Engineer, http://PalmPowerups.com
(847) 226 9295
AIM: hacker19180
MSN: [EMAIL PROTECTED]
ICQ: 165589894
Y! IM: dmitrygr2003

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

Reply via email to