Re: OT: computer arithmetic question on integer division

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux