Jump to content

Ethiopian multiplication: Difference between revisions

Forth, multiply step from colorForth
(→‎{{header|J}}: ++ a rather rough recursive haskell approach)
(Forth, multiply step from colorForth)
Line 117:
return 0;
}</lang>
 
=={{header|Forth}}==
<lang forth>
: e* ( x y -- x*y )
dup 0= if nip exit then
over 2* over 2/ recurse
swap 1 and if + else nip then ;
</lang>
 
The author of Forth, Chuck Moore, designed a similar primitive into his MISC Forth microprocessors. The '''+*''' instruction is a multiply step: it adds S to T if A is odd, then shifts both A and T right one. The idea is that you only need to perform as many of these multiply steps as you have significant bits in the operand. (See his [http://www.colorforth.com/inst.htm core instruction set] for details.)
 
=={{header|Fortran}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.