RPG/400 Help


Arithmetic Operations

The arithmetic operations are:

For examples of arithmetic operations, see Figure "Summary of Arithmetic Operations".

Remember the following when specifying arithmetic operations:

For arithmetic operations in which all three fields are used:

The length of any field specified in an arithmetic operation cannot exceed 30 digits. If the result exceeds 30 digits, digits are dropped from either or both ends, depending on the location of the decimal point.

All arithmetic operations are done algebraically.

The results of all operations are signed (a plus sign is a hexadecimal F and a minus sign is a hexadecimal D) according to the following rules. The sign is in the zone portion of the low-order byte.

For information on using arrays with arithmetic operations, see Specifying an Array in Calculations.

Addition: If factor 1 and factor 2 have like signs, the result field sign is the same. If factor 1 and factor 2 have unlike signs, the result field sign is the same as the sign of the factor with the larger absolute value.

Subtraction: Change the sign of factor 2, and apply the rules for addition.

Multiplication: If factor 1 and factor 2 have like signs, the result field sign is plus (+). If factor 1 and factor 2 have unlike signs, the result field sign is minus (-).

Division: If factor 1 and factor 2 have like signs, the result field sign is plus (+). If factor 1 and factor 2 have unlike signs, the result field sign is minus (-). The sign of the remainder is the same as the factor 1 sign.

For the ADD, SUB, MULT, and DIV operations, factor 1 is not required. If factor 1 is not specified, the operation is done as though factor 1 and the result field were the same field.


[ Top of Page | Previous Page | Next Page | Table of Contents ]