
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses


Task

Get two integers from the user,   and then (for those two integers), display their:

   sum 
   difference 
   product 
   integer quotient
   remainder 
   exponentiation   (if the operator exists) 


Don't include error handling.

For quotient, indicate how it rounds   (e.g. towards zero, towards negative infinity, etc.).

For remainder, indicate whether its sign matches the sign of the first operand or of the second operand, if they are different.




# Most of this long script is mere presentation.
# All you really need to do is push two integers 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