gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Division with a constant dividend

#28003 - DiscoStew - Mon Oct 25, 2004 10:40 pm

There have been numerous ways to do division, like bit-shifting to powers of 2, multiplying by a constant recipricol, and ASM. But here is a question...

What if the dividend is the constant, and the divisor is not a constant? Is there a fast way to figure out the result? It's simple is the divisor is still a power of 2, but what if it isn't?
_________________
DS - It's all about DiscoStew

#28004 - poslundc - Mon Oct 25, 2004 10:56 pm

The fastest way is using a reciprocal lookup-table. Having a constant numerator doesn't give you much of an advantage if the denominator is changing, unfortunately.

Dan.

#28014 - Gene Ostrowski - Tue Oct 26, 2004 4:32 am

Depending on the range of the numbers, a straight-up lookup table might work without having to do any multiply... what kind of numbers are you looking to divide?
_________________
------------------
Gene Ostrowski