Chapter 3
© 2000, The TRAC Foundation
Arithmetic Primitives
This chapter describes the arithmetic group of primitives.
3.1 Introduction to the Arithmetic Primitives
The integer Arithmetic group of primitives provides for 31-bit signed decimal integer arithmetic. Operands may have the minus sign prefix to indicate a negative number, or the plus sign prefix to indicate a positive number. The plus sign is unnecessary, however, since the default is a positive integer. The greatest magnitude of an operand is 2,147,483,647.
The arithmetic primitives are:
aa Integer add.
as Integer subtract.
am Integer multiply.
aq Integer quotient.
ar Integer remainder.
ag Greater than test.
3.2 Arithmetic Primitives Reference
This section provides the syntax, input arguments, value string, and description of each arithmetic primitive. The primitives appear in alphabetical order.
aa - Integer Add
syntax
:(aa,<op1>,<op2>)
Input Arguments
<op1> Signed integer.
<op2> Signed integer.
Description
The value-producing add primitive aa gives the sum of two signed integers. The primitive adds <opl> to <op2>, and produces as the value string an ASCII digit string expressing the signed sum of the input arguments.
Example
:(aa,5,3)'8
ag - Greater Than Test
Syntax
:(ag,<op1>,<op2>,<yes>,<eq>,<no>)
Input Arguments
<op1> Signed integer.
<op2> Signed integer.
<yes> Value string to produce if <opl> is greater than <op2>.
<eq> Value string to produce if <opl> is equal to <op2>.
<no> Value string to produce if <op1> is less than <op2>.
Description
The value-producing greater than primitive ag provides a test of the signed magnitudes of two integers. The primitive algebraically compares the signed quantities <op1> and <op2>.
The primitive produces as the value string one of the strings you specify with the <yes>, <eq>, or <no> arguments.
Example
:(ag, 16, 23, Yes, Same, No)'No
am - Integer Multiply
Syntax
:(am,<op1>,<op2>)
Input Arguments
<op1 > Signed integer multiplicand.
<op2> Signed integer multiplier.
Description
The value-producing multiply primitive am gives the product of the two signed integers <op1> and <op2>.
The primitive produces as the value string an ASCII digit string expressing the signed product of the input arguments.
Example
:(am, 35, 9)'1315
aq - Integer Quotient
syntax
(aq,<op1>,<op2>)
Input Arguments
<op1 > Signed integer dividend.
<op2> Signed integer divisor.
Description
The value-producing quotient primitive aq gives the integer quotient of two signed integers. The primitive divides <op1> by <op2> to form the quotient.
The primitive produces as the value string an ASCII digit string expressing the signed quotient of the input arguments.
Example
:(aq, 27, 3)'9
ar - Integer Remainder
syntax
:(ar,<op1>,<op2>)
Input Arguments
<op1> Signed integer dividend.
<op2> Signed integer divisor.
Description
The value-producing remainder primitive ar gives the remainder of two signed integers. The primitive divides <op1> by <op2>, and finds the remainder. The sign of the remainder is the sign of <op1>.
The primitive produces as the value string an ASCII digit string expressing the signed remainder of the input arguments.
Example
:(ar, 57, 5)'2
as - Integer Subtract
syntax
(as,<op1>,<op2>)
Input Arguments
<op1 > Signed integer.
<op2> Signed integer.
Description
The value-producing subtract primitive as gives the difference between two signed integers. The primitive subtracts <op2> from <op1>.
The primitive produces as the value string an ASCII digit string expressing the signed difference between the input arguments.
Example
:(as, 7, 3)'4