REXX has numerous math operators. There are operators to perform addition, subtraction, multiplication, division, raise to a power, etc. When REXX encounters some instruction containing a math operator (that is not enclosed in quotes), then REXX regards this as a mathematical expression. For example, here is a mathematical expression. (It uses the addition operator, which is simply a plus sign).
"5" + "3"
Note that the plus sign is not enclosed in quotes. This is therefore a math expression. It is the addition of two numeric strings "5" and "3".

Remember that base 10 numeric strings can also be expressed without quotes, so the following math expression is the same as the above:

5 + 3

When REXX encounters a math expression, it evaluates that expression to its resulting value and substitutes that value. In other words, if REXX sees the following instruction:

SAY 5 + 3
...it doesn't print 5 + 3. The plus sign is not a literal string (ie, enclosed within quotes). Therefore, REXX regards it as a math expression, evaluates it as 8, and subsequently prints out 8.

With math expressions, you can use whole numbers and decimal fractions. For example, the following REXX line prints 6.2.

SAY 5 + 1.2

Addition

The operator for addition is the plus sign +. Here's an example of adding the two numbers 2 and 14:

2 + 14

REXX evaluates the above to be 16.


Subtraction

The operator for subtraction is the minus sign -. Here's an example of subtracting 8 from 230:

230 - 8

REXX evaluates the above to be 222.


Multiplication

The operator for multiplication is the asterisk *. Here's an example of multiplying two numbers, 2 times 6:

2 * 6

REXX evaluates the above to be 12.


Division

For division, there are several operators you can use, depending upon what kind of answer you want. For a simple division, the operator is a single slash /. Here's an example of dividing 7 by 2:

7 / 2

REXX evaluates the above to be 3.5 (ie, 3 and a half). In other words, 2 goes into 7 three times and there's a remainder of one half of 2, or 1.

To divide for the purpose of getting only the remainder, the operator is two slashes //. Here's an example of dividing 7 by 2, in order to get the remainder:

7 // 2

REXX evaluates the above to be 1 (ie, after 2 goes into 7 three times, there is a remainder of 1).

To divide, and return only the whole number portion of an answer and no remainder, the operator is the percent sign %.

7 % 2

REXX evaluates the above to be 3 (ie, the decimal portion of the answer is discarded, so the answer is rounded down to a whole number).

Note: To get the reciprocal of a number, divide it into 1 (ie, the reciprocal of 20 is 1 / 20).


Raising to a power

To raise a number to a power, the operator is two asterisks **. Here's an example of raising 3 to the second power (ie, 3 squared):

3 ** 2

REXX evaluates the above to be 9.


Errata

Note: You don't need to place blank space inbetween numbers and operators. For example, the following 2 expressions are the same.

2 + 55
2+55

Variables can also be used in any mathematical expression, as we'll see later.