Objective
This example lists values obtained while computing the volume of a sphere, in cubic centimeters, from diameters measured in inches. The program releases a detail line after every second arithmetic operation.
Procedure
The program issues several arithmetic instructions to compute the volume of the sphere. CA Culprit automatically rounds the result of a calculation. As the results below indicate, the code should specify truncation for the arithmetic operations in this example.
Code
col. 2 ▼ IN 80 REC TANK-DIA-IN 1 3 010 RADIUS-IN 010 RADIUS-CM 010 WORK-FLD 010 CUBIC-CM 013 CALCULATING THE CC VOLUME OF A SPHERE FROM A DIAMETER IN INCHES 0152*010 TANK-DIA-IN HF 0152*020 RADIUS-IN HF 0152*030 RADIUS-CM HF 0152*040 WORK-FLD HF 0152*050 CUBIC-CM HF . . . 017 TANK-DIA / 2 RADIUS-IN 017 RADIUS-IN X 2.54 RADIUS-CM 017 RELS 2 017 COMPUTE (RADIUS-CM X RADIUS-CM X RADIUS-CM) WORK-FLD 017 WORK-FLD X 3.1416 WORK-FLD 017 RELS 2 017 WORK-FLD X 4 WORK-FLD 017 WORK-FLD / 3 CUBIC-CM 017 RELS 2 . . .
Result
The values released between calculations are:
TANK-DIA-IN RADIUS-IN RADIUS-CM WORK-FLD CUBIC-CM 15 8 20 15 8 20 25,133 15 8 20 100,532 33,511 45 24 60 125,665 33,511
The result should have been:
TANK-DIA-IN RADIUS-IN RADIUS-CM WORK-FLD CUBIC-CM 15 7.5 19.05 15 7.5 19.05 21,718.8 15 7.5 19.05 86,875.2 28,958.4 45 22.5 57.15 108,594.0 28,958.4
The released values show that rounding occurs in all calculations. Truncation should be indicated in the code for correct results.
|
Copyright © 2014 CA.
All rights reserved.
|
|