Arithmetic operators work on valid numeric constants or on variables
that represent valid numeric constants.
- Types of Numeric Constants
- 12
- A whole number has no decimal point or commas.
Results of arithmetic operations with whole numbers can contain a
maximum of nine digits unless you override the default with the NUMERIC
DIGITS instruction. For information about the NUMERIC DIGITS instruction,
see z/OS TSO/E REXX Reference. Examples of whole numbers are: 123456789 0 91221 999
- 12.5
- A decimal number includes a decimal point. Results
of arithmetic operations with decimal numbers are limited to a total
maximum of nine digits (NUMERIC DIGITS default) before and after
the decimal. Examples of decimal numbers are: 123456.789 0.888888888
- 1.25E2
- A floating point number in exponential notation, is sometimes called scientific notation. The number after the "E"
represents the number of places the decimal point moves. Thus 1.25E2
(also written as 1.25E+2) moves the decimal point to the right two
places and results in 125. When an "E" is followed by a minus (-),
the decimal point moves to the left. For example, 1.25E-2 is .0125.
Floating point numbers are used to represent very large or very small
numbers. For more information about floating point numbers, see z/OS TSO/E REXX Reference.
- -12
- A signed number with a minus (-) next to the number represents
a negative value. A plus next to a number indicates that the number
should be processed as it is written. When a number has no sign,
it is processed as a positive value.
The arithmetic operators you can use are as follows:
- Operator
- Meaning
- +
- Add
- -
- Subtract
- *
- Multiply
- /
- Divide
- %
- Divide and return a whole number without a remainder
- //
- Divide and return the remainder only
- **
- Raise a number to a whole number power
- -number
- Negate the number
- +number
- Add the number to 0
Using numeric constants and arithmetic operators, you can write
arithmetic expressions as follows:
7 + 2 /* result is 9 */
7 - 2 /* result is 5 */
7 * 2 /* result is 14 */
7 ** 2 /* result is 49 */
7 ** 2.5 /* result is an error */