Anonymous user
Arithmetic/Integer: Difference between revisions
no edit summary
m (→{{header|Sidef}}: updated the example) |
No edit summary |
||
Line 2,214:
a pow b = 6624737266949237011120128
ok
</pre>
=={{header|Onyx}}==
<lang onyx># Most of this long script is mere presentation.
# All you really need to do is push to intergers onto the stack
# and then execute add, sub, mul, idiv, or pow.
$ClearScreen { # Using ANSI terminal control
`\e[2J\e[1;1H' print flush
} bind def
$Say { # string Say -
`\n' cat print flush
} bind def
$ShowPreamble {
`To show how integer arithmetic in done in Onyx,' Say
`we\'ll use two numbers of your choice, which' Say
`we\'ll call A and B.\n' Say
} bind def
$Prompt { # stack: string --
stdout exch write pop flush
} def
$GetInt { # stack: name -- integer
dup cvs `Enter integer ' exch cat `: ' cat
Prompt stdin readline pop cvx eval def
} bind def
$Template { # arithmetic_operator_name label_string Template result_string
A cvs ` ' B cvs ` ' 5 ncat over cvs ` gives ' 3 ncat exch
A B dn cvx eval cvs `.' 3 ncat Say
} bind def
$ShowResults {
$add `Addition: ' Template
$sub `Subtraction: ' Template
$mul `Multiplication: ' Template
$idiv `Division: ' Template
`Note that the result of integer division is rounded toward zero.' Say
$pow `Exponentiation: ' Template
`Note that the result of raising to a negative power always gives a real number.' Say
} bind def
ClearScreen ShowPreamble $A GetInt $B GetInt ShowResults</lang>
{{out}}
<pre>
To show how integer arithmetic in done in Onyx,
we'll use two numbers of your choice, which
we'll call A and B.
Enter integer A: 34
Enter integer B: 2
Addition: 34 2 add gives 36.
Subtraction: 34 2 sub gives 32.
Multiplication: 34 2 mul gives 68.
Division: 34 2 idiv gives 17.
Note that the result of integer division is rounded toward zero.
Exponentiation: 34 2 pow gives 1156.
Note that the result of raising to a negative power always gives a real number.
</pre>
|