Please enable JavaScript to view this site.

A-Shell Reference

SCALE factor

The SCALE statement effectively shifts the significant digit window on floating point values by the specified factor—i.e. the specified number of digits—with the goal of reducing the rounding/precision problems inherent in floating point representation. The most common factor to use is 2, which shifts the window 2 decimals to the right, effectively multiplying by 100, causing values like 123.45 to be stored as 12345 instead. This can be a useful technique when using floating point values to store currency figures. But for most systems, it is an all-or-nothing affair because it affects the way floating point values are stored in files. If you access the same file from programs with different SCALE factors, you will end up with a mixture of values off by the differing factors of ten. Plus, for what you gain at one edge of the range, you lose at the other. For example, if you use SCALE 2 to reduce rounding problems with dollars and cents, you effectively also reduce, by the same two decimal places, the maximum dollar values you can reliably store without introducing the same kinds of rounding problems on the high end—i.e. reducing the maximum value you can reliably store in the eleven significant digits of F6 format from a hundred billion to one billion.

Because of the complications, risks and side effects, and because there are other better methods of dealing with rounding and precision, the use of SCALE is not recommended. But it remains supported for backwards compatibility with legacy applications. See the links below for other approaches to rounding and precision.

Note while SCALE is primarily a run-time mechanism, it also affects the way literal constants are stored within compiled programs. Also note that the position of the SCALE statement is critical; it should almost always appear before any other statement defining or using variables.

See Also:

History

2018 February, A-Shell 6.5.1628: SCALE is now inherited by SBX routines from the caller. Previously it was essential that the SBX specify the same SCALE factor in order to avoid problems with values getting shifted up or down by the SCALE factor.