Product Site

Chapter 10. Numbers and Arithmetic

10.1. Precision
10.2. Arithmetic Operators
10.2.1. Multiplication
10.2.2. Power
10.2.3. Integer Division
10.2.4. Remainder
10.2.5. Operator Examples
10.3. Exponential Notation
10.4. Numeric Comparisons
10.5. Whole Numbers
10.6. Whole Number Limits
10.7. Arithmetic Errors

This chapter gives an overview of the arithmetic facilities of the Rexx language.

Numbers can be expressed flexibly. Leading and trailing whitespace characters are permitted, and exponential notation can be used. Valid numbers are, for example:
Example 10.1. Numbers
12             /* a whole number                      */
"-76"          /* a signed whole number               */
12.76          /* decimal places                      */
" +  0.003 "   /* blanks around the sign and so forth */
17.            /* same as 17                          */
.5             /* same as 0.5                         */
4E9            /* exponential notation                */
0.73e-7        /* exponential notation                */

Ignoring Exponential Notation, a number in Rexx is defined as follows:
whitespace

are one or more blanks or horizontal tab characters.
sign

is either + or -.
digits

are one or more of the decimal digits 0-9.

Note that a single period alone is not a valid number.

The arithmetic operators include addition (+), subtraction (-), multiplication (*), power (**), division (/), prefix plus (+), and prefix minus (-). In addition, it includes integer divide (%), which divides and returns the integer part, and remainder (//), which divides and returns the remainder. For examples of the arithmetic operators, see Section 10.2.5, “Operator Examples”.

The result of an arithmetic operation is formatted as a character string according to specific rules. The most important rules are: