Previous Next Chapter

Arithmetic Operators

An important class of operands are those representing numbers. Numbers consist of the character 0-9, a period (.), plus sign (+), minus sign (-), and blanks. To indicate exponential notation, a number may be followed by an "e" or "E" and a (signed) integer.

Both strings and symbols may be used to specify numbers. Since the language is typeless, variables do not have to be declared as numeric before use in an arithmetic operation. Instead, each value string is examined when it is used in order to verify that it represents a number. The following examples are all valid numbers:

33
" 12.3 "
0.321e12
` + 15. `

Leading and trailing blanks are permitted. Blanks may be embedded between a plus (+) or minus (-) sign and the number, but not within the number itself.

You can modify the basic precision used for arithmetic calculations while a program is executing. The number of significant figures used in arithmetic operations is determined by the Numeric Digits setting and may be modified using the NUMERIC instruction described in Chapter 4.

The number of decimal places used for a result depends on the operation and the number of decimal places in the operands. ARexx preserves trailing zeroes to indicate the precision of the result. If the total number of digits required to express a value exceeds the current Numeric Digits setting, the number is formatted in exponential notation. They are:

Table 3-1. Arithmetic Operators

Operator Priority Example Result

+ (prefix conversion) 8 `3.12' 3.12

- (prefix negation) 8 -"3.12 "-3.12

** (exponentiation) 7 0.5**3 0.125

* (multiplication) 6 1.5*1.50 2.250

/ (division) 6 6 / 3 2

% (integer division) 6 -8 % 3 -2

// (remainder) 6 5.1//0.2 7.15

+ (addition) 5 3.1+4.05 7.15

-(subtraction) 5 5.55 - 1 4.55

Top Previous Next Chapter