Chapter 10. Numbers and Arithmetic

Table of Contents
Arithmetic Operators
Exponential Notation
Numeric Comparisons
Limits and Errors when Rexx Uses Numbers Directly

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:

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                */

A number in Rexx is defined as follows:

   +-whitespace-+  +-sign--+------------+-+  +-digits.digits-+
                           +-whitespace-+    +-.digits-------+



are one or more blanks or horizontal tab characters.


is either + or -.


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 Operator Examples.

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


Precision is the maximum number of significant digits that can result from an operation. This is controlled by the instruction:

>>-NUMERIC DIGITS--+------------+--;---------------------------><

The expression is evaluated and must result in a positive whole number. This defines the precision (number of significant digits) of a calculation. Results are rounded to that precision, if necessary.

If you do not specify expression in this instruction, or if no NUMERIC DIGITS instruction has been processed since the start of a program, the default precision is used. The Rexx standard for the default precision is 9. The default may be overridden on a source-file basis using the ::OPTIONS directive.

NUMERIC DIGITS can set values smaller than nine. However, use small values with care because the loss of precision and rounding affects all Rexx computations, including, for example, the computation of new values for the control variable in DO loops.