Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2070
Number of posts: 5361

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
* or /? Which is faster? Posted by BenGmo on 31 Jan 2000 at 8:06 PM
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.


Edit Report
Re: * or /? Which is faster? Posted by The Watcher^TUHB on 1 Feb 2000 at 3:37 AM
: 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.<br>
: <br>
<br>
<br>
Depends, would you call about ten times as fast faster or slower? *grin*. go for the fmul. Always. <br>



Edit Report
Re: Re: * or /? Which is faster? Posted by Zeppo on 1 Feb 2000 at 11:00 AM
A tip!<br>
<br>
If you want to divide, or multiply a number<br>
by a factor that equals n^2 e.g (1, 2, 4, 8, 16..)<br>
use SHL(SHiftLeft) for multiplication, and<br>
SHR(SHiftRight) for division.<br>
<br>
//-------<br>
int x = 12 >> 1; // x is now (12 / 1^2) = 6<br>
int x = 12 << 2; // x is now (12 * 2^2) = 48<br>
//-------<br>
<br>
REMEMBER! it's for int numbers =)<br>
(int)floatVar << x, should work though.<br>
<br>
<br>
SHR, and SHL can speed up programs SO! much..<br>
Trust me.<br>
Always try to get rid of the "*", and "/"<br>
You can use lookuptables with fixed-point math.<br>
//-----------<br>
<br>
float u = x/y * 1024 // x/y << 10<br>
long int z = u;<br>
printf("%f", (float)(u >> 10));<br>
<br>
//-----------<br>
try something like this.<br>
hope this stuff helps.<br>
<br>
<br>



Edit Report
Re: Re: Re: * or /? Which is faster? Posted by BenGmo on 2 Feb 2000 at 9:00 PM
Thanks a lot guys/gals. BTW, any idea why division is ten times slower?


Edit Report
Re: Re: Re: Re: * or /? Which is faster? Posted by Jessie James on 8 Mar 2000 at 5:45 PM
Who gives a rat's ass?<br>
<br>
: Thanks a lot guys/gals. BTW, any idea why division is ten times slower?<br>
: <br>
<br>



Edit Report
Re: Re: Re: * or /? Which is faster? Posted by BenGmo on 2 Feb 2000 at 9:01 PM
Thanks a lot guys/gals. BTW, any idea why division is ten times slower? Seems a little much, you aren't exagerating are you?





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.