10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9.2 Enhancements to modular arithmetic 447<br />

if(s ≥ N) s = s − N;<br />

}<br />

return s;<br />

The binary divide and mul-mod algorithms, though illuminating, suffer<br />

from a basic practical shortcoming: One is not taking due advantage of<br />

multiple-bit arithmetic as is commonly available on any reasonably powerful<br />

computer. One would like to perform multiple-bit operations within machine<br />

registers, rather than just operating one bit at a time. For this reason, larger<br />

bases than B = 2 are usually used, and many modern div implementations<br />

invoke “Algorithm D,” see [Knuth 1981, p. 257], which is a finely tuned version<br />

of the classical long division. That algorithm is a good example of one that<br />

has more pseudocode complexity than does our binary Algorithm (9.1.3), yet<br />

amounts to a great deal of optimization in actual programs.<br />

9.2 Enhancements to modular arithmetic<br />

The classical div and mod algorithms discussed in Section 9.1.3 all involve<br />

some sort of explicit divide operation. For the binary algorithms given, this<br />

division is trivial; that is, if 0 ≤ a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!