* or /? Which is faster? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

* or /? Which is faster?

Which is faster, multiplication or division? Does it matter? Say i had to divide a lot of numbers by 3. Would it be faster to multiply them by 0.333333333? Lets assume that all the numbers are floats.


Comments

  • : Which is faster, multiplication or division? Does it matter? Say i had to divide a lot of numbers by 3. Would it be faster to multiply them by 0.333333333? Lets assume that all the numbers are floats.

    :





    Depends, would you call about ten times as fast faster or slower? *grin*. go for the fmul. Always.




  • A tip!



    If you want to divide, or multiply a number

    by a factor that equals n^2 e.g (1, 2, 4, 8, 16..)

    use SHL(SHiftLeft) for multiplication, and

    SHR(SHiftRight) for division.



    //-------

    int x = 12 >> 1; // x is now (12 / 1^2) = 6

    int x = 12 << 2; // x is now (12 * 2^2) = 48<br>
    //-------



    REMEMBER! it's for int numbers =)

    (int)floatVar << x, should work though.<br>




    SHR, and SHL can speed up programs SO! much..

    Trust me.

    Always try to get rid of the "*", and "/"

    You can use lookuptables with fixed-point math.

    //-----------



    float u = x/y * 1024 // x/y << 10<br>
    long int z = u;

    printf("%f", (float)(u >> 10));



    //-----------

    try something like this.

    hope this stuff helps.








  • Thanks a lot guys/gals. BTW, any idea why division is ten times slower?


  • Thanks a lot guys/gals. BTW, any idea why division is ten times slower? Seems a little much, you aren't exagerating are you?


  • Who gives a rat's ass?



    : Thanks a lot guys/gals. BTW, any idea why division is ten times slower?

    :






Sign In or Register to comment.