unsigned long udivmodsi4(unsigned long num, unsigned long den, int modwanted) | |
{ | |
unsigned long bits = 1; | |
unsigned long ret = 0; | |
unsigned long tmpnum = num; | |
unsigned long tmpden = den; | |
while (tmpden < tmpnum && bits && !(tmpden & (1L<<31))) | |
{ | |
tmpden <<=1; | |
bits <<=1; | |
} | |
while (bits) | |
{ | |
if (tmpnum >= tmpden) | |
{ | |
tmpnum -= tmpden; | |
ret |= bits; | |
} | |
bits >>=1; | |
tmpden >>=1; | |
} | |
if (modwanted) return tmpnum; | |
return ret; | |
} |