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

division... slow?

Name: Anonymous 2006-09-25 16:25

In a lot of videogame code, whenever a lot of numbers are to be divided by one number, I usually see this:

inv = 1.0 / divisor;
...and then all the numbers * by inv

rather than all the numbers being / by divisor.

I'm guessing, at the CPU level, division is slightly slower and less efficient than multiplication?  I can't really think of any other reason why someone would do this.

Name: Anonymous 2006-09-25 17:25

If divisor is a constant, and your compiler is not smart enough, this should increase performance. Division is more costly than multiplication. Depending on the processor design, the difference can be very large.

Name: Anonymous 2006-09-25 17:44

>>2
>If divisor is a constant, and your compiler is not smart enough

That must be some compiler.

Name: Anonymous 2006-09-25 22:43

its because a computer thinks in base 2, while we do it in base 10. So some simple base 10 decimals are harder to convert as base 2 decimals

Name: Anonymous 2006-09-25 22:54

>>4
God, just don't even post if you're going to say something this stupid.

Name: Anonymous 2006-09-26 5:29

>>4
Whut

Name: Anonymous 2006-09-26 11:05

>>4
It has nothing whatsoever to do with base conversions. Don't be so retarded.

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