Rational Developer for System z
Enterprise COBOL for z/OS, Version 4.1, Programming Guide


Example: exponentiation in fixed-point arithmetic

The following example shows how the compiler performs an exponentiation to a nonzero integer power as a succession of multiplications, storing intermediate results as needed.

COMPUTE Y = A ** B

If B is equal to 4, the result is computed as shown below. The values of i and d that are used are calculated according to the multiplication rules for fixed-point data and intermediate results (referred to below).

  1. Multiply A by A yielding ir1.
  2. Multiply ir1 by A yielding ir2.
  3. Multiply ir2 by A yielding ir3.
  4. Move ir3 to ir4.

    ir4 has dmax decimal places. Because B is positive, ir4 is moved to Y. If B were equal to -4, however, an additional fifth step would be performed:

  5. Divide ir4 into 1 yielding ir5.

ir5 has dmax decimal places, and would then be moved to Y.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)