Overflow in numeric expressions

Overflow in a numeric expression occurs when an intermediate or final result of the expression it too large to be stored by the type of data used in the expression. This is especially common with integer values.

For example, multiplying the integers 450 and 75 should result in the value 33,750, but instead results in -31,786. Because the actual result is larger than 32,767, the maximum amount that can be represented by an integer in Dexterity, overflow occurs.

One method of preventing overflow is to convert all integer values in the expression to long integers and then evaluate the expression. All integers in the expression, not just the final result, must be converted to long integers to avoid overflow. This is because the overflow can occur in intermediate steps while evaluating the expression, not only the final step. For example, the expression in the following script would still overflow:

local long product;

product = 450 * 75;

To avoid the overflow, the two integer values must also be converted to long integers as shown in the following script:

local long product, operand1, operand2;

operand1 = 450;
operand2 = 75;
product = operand1 * operand2;

Documentation Feedback