Jump to content

Arithmetic/Integer: Difference between revisions

Added Piet Example
No edit summary
(Added Piet Example)
Line 1,197:
(prinl "Modulus " (% A B)) # Sign of the first operand
(prinl "Power " (** A B)) )</lang>
=={{header|Piet}}==
 
[[File:PietArithmaticInteger.png]]
<code>
command stack
in(int) A
duplicate AA
duplicate AAA
duplicate AAAA
duplicate AAAAA
in(int) BAAAAA
duplicate BBAAAAA
duplicate BBBAAAAA
duplicate BBBBAAAAA
duplicate BBBBBAAAAA
push 9 9BBBBBAAAAA
push 1 19BBBBBAAAAA
roll BBBBAAAABA
push 7 7BBBBAAAABA
push 1 17BBBBAAAABA
roll BBBAAABABA
push 5 5BBBAAABABA
push 1 15BBBAAABABA
roll BBAABABABA
push 3 3BBAABABABA
push 1 13BBAABABABA
roll BABABABABA
add (A+B)BABABABA
out(int) BABABABA
sub (A-B)BABABA
out(int) BABABA
mult (A*B)BABA
out(int) BABA
divide (A/B)BA
out(int) BA
mod (A%B)
out(int) NULL
exit</code>
How rounding is handled is up to the interpreter, but I believe the intent was round towards 0.
=={{header|PL/I}}==
<lang PL/I>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.