OT: computer arithmetic question on integer division

Paul paul at all-the-johnsons.co.uk
Tue Jan 18 07:35:37 UTC 2005


Hi,

> > Does anyone know how the computer *actually* does integer
> > division? I understand that with powers of 2, it just does bit
> > shifting, but what about other powers, do you know?
> > 
> > (for example, 5/2 = 101/10 so shift the 101 by 1 and get 10, but how
> > does 5/3 work, lets say?)
> 
> You need to look at the assembly code.  Some compilers will see the
> constant (example 2 ) do a shift or other optimization.  With
> variables in the compiler might have to use the div (idiv) instruction.
> With constants interesting optimizations take place.

I'm not sure how it's done, but if you do a google search on
"Lame"+"RISC OS" you will find an integer maths library in there. As I
say, I don't know if it's done in assembler or C, but it may be worth a
look.

TTFN

Paul
-- 
"I don't know how World War III will be fought, but I do know World War
IV will be fought with sticks and stones" - Einstein
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20050118/e31eb88b/attachment-0001.sig>


More information about the fedora-list mailing list