16.12.2012 Views

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

c<br />

v A function is a sequence of instructions that calculates a single value. A list of<br />

zero or more values enclosed in parentheses always follow a function name, as<br />

in my_func(3.14159). See Functions.<br />

v An array is a list of values. Values in the list are called elements of the array.<br />

These elements are numbered, beginning at zero. We call such a number a<br />

subscript, or index, of the array. Subscripts always appear in square brackets<br />

after the array. For example, a[0] refers to element zero in the array a. The first<br />

element of the array always has the subscript 0. If a subscript value is a<br />

floating-point number, the fractional part is discarded to make the subscript into<br />

an integer. For example, the following expressions all refer to the same element:<br />

a[3] a[3.2] a[3.999]<br />

The maximum number of elements in a bc array is in the range from 0 to<br />

{BC_DIM_MAX}−1 inclusive. Unlike with many languages, you don’t need to<br />

declare the size of an array. Elements are created dynamically as required, with<br />

an initial value of zero.<br />

Since parentheses always follow function names and square brackets always follow<br />

array names, bc can distinguish between all three types of names—variable names,<br />

function names, and array names. Therefore, you can have variables, functions,<br />

and arrays with the same name. For example, foo may be a variable whereas foo()<br />

is a function and foo[ ] is an array.<br />

Built-in Variables<br />

bc has a number of built-in variables that are used to control various aspects of the<br />

interpreter. These are described in the following topics.<br />

Scale<br />

The scale value is the number of digits to be retained after the decimal point in<br />

arithmetic operations. For example, if the scale is 3, each calculation retains at least<br />

three digits after the decimal point. This means that:<br />

5 / 3<br />

has the value:<br />

1.666<br />

If –l is specified, the scale is set to 20; otherwise, the default scale is zero.<br />

The variable scale holds the current scale value. To change scales, assign a new<br />

value to scale, as in:<br />

scale = 5<br />

Since scale is just a regular bc variable, it can be used in the full range of bc<br />

expressions.<br />

The number of decimal places in the result of a calculation is affected not only by<br />

the scale, but also by the number of decimal places in the operands of the<br />

calculation. discusses this. Arithmetic Operations discusses this.<br />

There is also a function scale, which can determine the scale of any expression.<br />

For example, scale(1.1234) returns the result 4, which is the scale of the number<br />

1.1234. The result of the scale function is always an integer (that is, it has the<br />

scale of 0).<br />

52 z/<strong>OS</strong> <strong>V1R9.0</strong> <strong>UNIX</strong> <strong>System</strong> <strong>Services</strong> <strong>Command</strong> Reference

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!