2b426cfaa2
These bits are taken from the FSF anoncvs repo on 1-Feb-2002 08:20 PST.
25 lines
384 B
C
25 lines
384 B
C
unsigned long
|
|
udivmodsi4(unsigned long num, unsigned long den, int modwanted)
|
|
{
|
|
unsigned long bit = 1;
|
|
unsigned long res = 0;
|
|
|
|
while (den < num && bit && !(den & (1L<<31)))
|
|
{
|
|
den <<=1;
|
|
bit <<=1;
|
|
}
|
|
while (bit)
|
|
{
|
|
if (num >= den)
|
|
{
|
|
num -= den;
|
|
res |= bit;
|
|
}
|
|
bit >>=1;
|
|
den >>=1;
|
|
}
|
|
if (modwanted) return num;
|
|
return res;
|
|
}
|