All arithmetic operators force M to evaluate the expressions to which they apply as numeric. The arithmetic operators are:
+ as a unary operator simply forces M to evaluate the expression following as numeric; as a binary operator it causes M to perform addition.
- as a unary operator causes M to negate the expression following; as a binary operator it causes M to perform subtraction.
* binary operator for multiplication.
** binary operator for exponentiation.
/ binary operator for fractional division.
\ binary operator for integer division.
# binary operator for modulo, that is, causes M to produce the remainder from integer division of the first argument by the second.
Remember that precedence is left to right for all arithmetic operators.
Example:
GTM>WRITE 1+1 2 GTM>WRITE 2-1 1 GTM>WRITE 2*2 4 GTM>WRITE 3**2 9 GTM>WRITE 4/2 2 GTM>WRITE 7 2 GTM>WRITE 7#3 1 GTM>
This simple example demonstrates how each arithmetic binary operation uses numeric literals.
Example:
GTM>WRITE +"12ABC" 12 GTM>WRITE --"-3-4" -3 GTM>
The first WRITE shows the unary plus sign (+) operation forcing the numeric evaluation of a string literal. The second WRITE demonstrates the unary minus sign (-). Note the second minus sign within the string literal does not cause subtraction, but rather, terminates the numeric evaluation with the result of negative three (-3). Each of the leading minus signs causes one negation and therefore, the result is negative three (-3).