Arithmetic/Integer: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: changed the program (for validating the input), add/changed comments and whitespace.) |
|||
Line 2,621: | Line 2,621: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX pgm gets 2 integers from the C |
<lang rexx>/*REXX pgm gets 2 integers from the C,L. or via prompt; shows some operations.*/ |
||
numeric digits 20 /* |
numeric digits 20 /*#s are round at 20th significant dig.*/ |
||
parse arg x y . /*maybe the integers are on the C.L. */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
parse pull x y . |
|||
end |
|||
⚫ | |||
⚫ | |||
do while \datatype(x,'W') | \datatype(y,'W') /*both X and Y must be ints.*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
call show ' |
call show 'addition' , "+", x+y |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
parse value x y with y x /*swap the two values |
parse value x y with y x /*swap the two values and perform again*/ |
||
if j==1 then say copies('═', 79) /*display a fence after the 1st round. */ |
|||
⚫ | |||
end /*j*/ |
|||
exit /*stick a fork in it, we're done.*/ |
|||
⚫ | |||
/*──────────────────────────────────SHOW subroutine─────────────────────*/ |
|||
/*────────────────────────────────────────────────────────────────────────────*/ |
|||
show: parse arg what,oper,value,comment |
|||
say right( |
show: parse arg c,o,#,?; say right(c,25)' ' x center(o,4) y ' ───► ' # ?; return</lang> |
||
⚫ | |||
return</lang> |
|||
⚫ | |||
<pre> |
<pre> |
||
addition |
addition 4 + -17 ───► -13 |
||
subtraction |
subtraction 4 - -17 ───► 21 |
||
multiplication |
multiplication 4 * -17 ───► -68 |
||
int division |
int division 4 % -17 ───► 0 [rounds down] |
||
real division |
real division 4 / -17 ───► -0.23529411764705882353 |
||
division remainder 4 // -17 ───► 4 [sign from 1st operand] |
|||
power |
power 4 ** -17 ───► 5.8207660913467407227E-11 |
||
═══════════════════════════════════════════════════════════════════════════════ |
|||
addition - |
addition -17 + 4 ───► -13 |
||
subtraction - |
subtraction -17 - 4 ───► -21 |
||
multiplication - |
multiplication -17 * 4 ───► -68 |
||
int division - |
int division -17 % 4 ───► -4 [rounds down] |
||
real division - |
real division -17 / 4 ───► -4.25 |
||
division remainder -17 // 4 ───► -1 [sign from 1st operand] |
|||
power - |
power -17 ** 4 ───► 83521 |
||
</pre> |
</pre> |
||