skip to main content

Procedure Division : Common phrases and features for statements : Arithmetic statements

Arithmetic statements
The arithmetic statements are the ADD, COMPUTE, DIVIDE, MULTIPLY, and SUBTRACT Statements. They have several common features.
1.
2.
For ADD, DIVIDE, MULTIPLY, and SUBTRACT Statements when native arithmetic is in effect:
a.
b.
3.
 
NOTE - When standard arithmetic is in effect, a size error condition may occur during the execution of arithmetic operations used to compute the result as well as during the final move.
 
4.
a.
b.
When resolving addition and subtraction operations with decimal values, if all operands are equal or smaller than 18 digits in size, the result is internally stored into a Java long item, even if it would require more space. When one or more of the operands are greater than 18 digits in size, instead, the result is internally stored into a internal object that is slower than Java long but provides better precision. Due to this rule, if the program needs to handle numbers over 18 digits in size, it's strongly suggested to make the involved numeric variables greater than 18 digits in size, or the results may be incorrect in the decimal part.
The following code causes incorrect result:
01 W1 PIC 9(18).
01 W2 PIC 9(4)v9(4).
01 W3 PIC 9(18)v9(4).
MOVE 111111111111111111 TO W1.
MOVE 3333.5555 TO W2.
ADD W1 TO W2 GIVING W3.
In order to obtain the correct result, W1 should be defined greater than 18 digits, for example:
01 W1 PIC 9(19).
or, alternatively, iscobol.math.fpp36 (boolean) should be set to true in the configuration.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left