Choosing efficient computational data items

When you use a data item mainly for arithmetic or as a subscript, code USAGE BINARY on the data description entry for the item. The operations for manipulating binary data are faster than those for manipulating decimal data.

However, if a fixed-point arithmetic statement has intermediate results with a large precision (number of significant digits), the compiler uses decimal arithmetic anyway, after converting the operands to packed-decimal, decimal floating point, or vector decimal form. For fixed-point arithmetic statements, the compiler normally uses binary arithmetic for simple computations with binary operands if the precision is eight or fewer digits. Above 18 digits, the compiler always uses decimal arithmetic. With a precision of nine to 18 digits, the compiler uses either form.

To produce the most efficient code for a BINARY data item, ensure that it has:

  • A sign (an S in its PICTURE clause)
  • Eight or fewer digits

For a data item that is larger than eight digits or is used with DISPLAY or NATIONAL data items, use PACKED-DECIMAL. The code generated for PACKED-DECIMAL data items can be as fast as that for BINARY data items in some cases, especially if the statement is complicated or specifies rounding.

To produce the most efficient code for a PACKED-DECIMAL data item, ensure that it has:

  • A sign (an S in its PICTURE clause)
  • An odd number of digits (9s in the PICTURE clause), so that it occupies an exact number of bytes without a half byte left over
  • 15 or fewer digits in the PICTURE specification on ARCH(7) machines. If a PACKED-DECIMAL data item has more than 31 digits, library routines are used. For a PACKED-DECIMAL data item with 16-31 digits on ARCH(8) or higher level machines, the compiler uses instructions that are more efficient than library calls, but not as fast as if the data item has 15 or fewer digits.