Modular arithmetic: Difference between revisions

m
No edit summary
Line 560:
<pre>
\ We would normally define operators that have a suffix `m' in order
\ not to be confused: +m -m *m /m **m
\ Also useful is %:m reduce a number modulo.
 
Line 585:
: _reduce_1- 1- >R >R R@ *m R> R> ;
: _reduce_2/ 2/ >R DUP *m R> ;
( a b -- apowbn )
: **m 1 ROT ROT BEGIN DUP 1 AND IF _reduce_1- THEN
_reduce_2/ DUP 0= UNTIL 2DROP ; ( a b -- apowbn )
 
\ The solution is
13 set-modulus
 
10 DUP 100 **m +m 1 +m . CR
 
Line 609 ⟶ 610:
 
</pre>
 
=={{header|Go}}==
Go does not allow redefinition of operators. That element of the task cannot be done in Go. The element of defining f so that it can be used with any ring however can be done, just not with the syntactic sugar of operator redefinition.