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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

define sum_c(a[ ],b[ ],l) {<br />

auto i<br />

for (i=0; i < l; ++i) c[i] = a[i] + b[i]<br />

}<br />

refers to an external array named c, which is the element-by-element sum of two<br />

other arrays. If c did not exist prior to calling sum_c, it is created dynamically. After<br />

the program has called sum_c, statements in the program or in functions can refer<br />

to array c.<br />

Functions usually require a return statement. This has the form:<br />

return (expression)<br />

The argument expression is evaluated and used as the result of the function. The<br />

expression must have a single numeric value; it cannot be an array.<br />

A return statement ends a function, even if there are more statements left in the<br />

function. For example:<br />

define abs(i) {<br />

if (i < 0) return (-i)<br />

return (i)<br />

}<br />

is a function that returns the absolute value of its argument. If i is less than zero,<br />

the function takes the first return; otherwise, it takes the second.<br />

A function can also end by running the last statement in the function. If so, the<br />

result of the function is zero. The function sum_c is an example of a function that<br />

does not have a return statement. The function does not need a return statement,<br />

because its work is to calculate the external array c, not to calculate a single value.<br />

Finally, if you want to return from a function, but not return a value you can use<br />

return() or simply return. If there are no parameters to the return statement, a<br />

default value of zero is returned.<br />

Built-in Functions<br />

bc has a number of built-in functions that perform various operations. These<br />

functions are similar to user-defined functions. You do not have to define them<br />

yourself, however; they are already set up for you. These functions are:<br />

length(expression)<br />

Calculates the total number of decimal digits in expression. This includes<br />

digits both before and after the decimal point. The result of length() is an<br />

integer. For example, length(123.456) returns 6.<br />

scale(expression)<br />

Returns the scale of expression. For example, scale(123.456) returns 3.<br />

The result of scale() is always an integer. Subtracting the scale of a<br />

number from the length of a number lets you determine the number of digits<br />

before the decimal point.<br />

sqrt(expression)<br />

Calculates the square root of the value of expression. The result is<br />

truncated in the least significant decimal place (not rounded). The scale of<br />

the result is the scale of expression, or the value of scale(), whichever is<br />

larger.<br />

You can use the following functions if –l is specified on the command line. If it is<br />

not, the function names are not recognized. There are two names for each function:<br />

bc<br />

Chapter 2. Shell command descriptions 61

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

Saved successfully!

Ooh no, something went wrong!