Modular arithmetic: Difference between revisions

Content added Content deleted
Line 84: Line 84:


The following program uses the <code>unsigned __int128</code> type of GNU C. It could easily be modified, however, not to use that. I use the compiler extension to implement multiplication that, for all the ordinary integer types on AMD64, does not overflow.
The following program uses the <code>unsigned __int128</code> type of GNU C. It could easily be modified, however, not to use that. I use the compiler extension to implement multiplication that, for all the ordinary integer types on AMD64, does not overflow.

I would be tempted to say that supporting modulus 2**(wordsize) amounts to transparently supporting both modular and non-modular integers. It is, after all, the normal arithmetic of the language. However, 10**100 would overflow the register. There is, in fact, with C semantics, no way to do non-modular arithmetic with unsigned integers of fixed size! You automatically get 2**(wordsize) as a modulus.


<syntaxhighlight lang="ATS">
<syntaxhighlight lang="ATS">