Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

If Angry Birds took 4 people to make

Name: Anonymous 2011-10-28 14:44

what the fuck can one person do by themselves? I need friends...

Name: Anonymous 2011-10-29 17:29

>>4
Actually, depending on how smart your compiler is, 1 / 4 * AngryBirds is either as fast or faster than AngryBirds / 4 in most scenarios.

Division is a much more computationally expensive than multiplication, so much so that many low-powered ARM cores don't even include a division instruction. Assuming that you're working with floating point values, it's always faster to multiply by the reciprocal of your divisor than to perform naive division.

``But wait!'' you say, ``if the program has to divide 1 by 4 first to get that reciprocal, wouldn't that defeat the purpose of the multiplication optimization?'' Indeed, you would be correct, but fortunately, nearly all compilers are smart enough not to do that. The parser sees 1 / 4 and immediately replaces it with .25 before compilation, much in the same way as macro substitution is performed.

However, if your compiler is really smart, it will see AngryBirds / 4 and compile it as .25 * AngryBirds instead, in which case it didn't matter what we wrote. If you were working with integer division, on the other hand, it might interest you to visit the following link, which describes algorithm (with a public domain C implementation) for applying a similar trick to arbitrary integers at run-time, not compile time. Now that's OPTIMIZED.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List