Arithmetic/Integer: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|ALGOL 68}}: ALGOL 68R has a non-standard '%:=' operator - update) |
||
Line 484: | Line 484: | ||
<lang algol68>main:( |
<lang algol68>main:( |
||
LONG INT a=355, b=113; |
LONG INT a=355, b=113; |
||
printf(($"a+b = "gl$, a + b)); |
printf(($"a PLUS b = a+b = "gl$, a + b)); |
||
printf(($"a-b = "gl$, a - b)); |
printf(($"a MINUS b = a-b = "gl$, a - b)); |
||
printf(($"a*b = a×b = "gl$, a * b)); |
printf(($"a TIMES b = a*b = a×b = "gl$, a * b)); |
||
printf(($"a/b = "gl$, a / b)); |
printf(($"a DIV b = a/b = "gl$, a / b)); |
||
printf(($"a OVER b = a%b = a÷b = "gl$, a % b)); |
printf(($"a OVER b = a%b = a÷b = "gl$, a % b)); |
||
printf(($"a MOD b = a%*b = a%×b = a÷×b = a÷*b = "gl$, a %* b)); |
printf(($"a MOD b = a%*b = a%×b = a÷×b = a÷*b = "gl$, a %* b)); |
||
Line 494: | Line 494: | ||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
a+b = +468 |
a PLUS b = a+b = +468 |
||
a-b = +242 |
a MINUS b = a-b = +242 |
||
a*b = a×b = +40115 |
a TIMES b = a*b = a×b = +40115 |
||
a/b = +3.141592920353982300884955752e +0 |
a DIV b = a/b = +3.141592920353982300884955752e +0 |
||
a OVER b = a%b = a÷b = +3 |
a OVER b = a%b = a÷b = +3 |
||
a MOD b = a%*b = a%×b = a÷×b = a÷*b = +16 |
a MOD b = a%*b = a%×b = a÷×b = a÷*b = +16 |
||
a UP b = a**b = a↑b = +1.499007808785573768814747570e+288 |
a UP b = a**b = a↑b = +1.499007808785573768814747570e+288 |
||
</pre> |
</pre> |
||
[[ALGOL 68R]] has a non-standard ' |
[[ALGOL 68R]] has a non-standard '%:=' operator. This operator |
||
is equivalent to the OVERAB operator of the revised report, except it delivers the remainder as a result. |
is equivalent to the OVERAB operator of the revised report, except it delivers the remainder as a result. |
||
So a '/:=' b sets a to the quotient of a%b and returns the remainder of a%b as a result (Note "%" is the division operator in Algol 68, not the modulo operator - it can also be written as OVER). |
So a '/:=' b sets a to the quotient of a%b and returns the remainder of a%b as a result (Note "%" is the division operator in Algol 68, not the modulo operator - it can also be written as OVER). |
||
This operator must be "stropped" i.e. enclosed in single quotes. eg. |
This operator must be "stropped" i.e. enclosed in single quotes. eg. |
||
INT quotient:=355, remainder; |
INT quotient:=355, remainder; |
||
remainder := quotient |
remainder := quotient %:= 113; |
||
Sets quotient to 3, remainder to 16. |
Sets quotient to 3, remainder to 16. |
||