lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | |
2 | unsigned long udivmodsi4(unsigned long num, unsigned long den, int modwanted) | ||||
3 | { | ||||
4 | unsigned long bits = 1; | ||||
5 | unsigned long ret = 0; | ||||
6 | unsigned long tmpnum = num; | ||||
7 | unsigned long tmpden = den; | ||||
8 | |||||
9 | while (tmpden < tmpnum && bits && !(tmpden & (1L<<31))) | ||||
10 | { | ||||
11 | tmpden <<=1; | ||||
12 | bits <<=1; | ||||
13 | } | ||||
14 | while (bits) | ||||
15 | { | ||||
16 | if (tmpnum >= tmpden) | ||||
17 | { | ||||
18 | tmpnum -= tmpden; | ||||
19 | ret |= bits; | ||||
20 | } | ||||
21 | bits >>=1; | ||||
22 | tmpden >>=1; | ||||
23 | } | ||||
24 | if (modwanted) return tmpnum; | ||||
25 | |||||
26 | return ret; | ||||
27 | } |