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.

c<br />

Arithmetic Operations<br />

bc provides a large number of arithmetic operations. Following standard arithmetic<br />

conventions, some operations are calculated before others. For example,<br />

multiplications take place before additions unless you use parentheses to group<br />

operations. Operations that take place first are said to have a higher precedence<br />

than operations that take place later.<br />

Operations also have an associativity. The associativity dictates the order of<br />

evaluation when you have a sequence of operations with equal precedence. Some<br />

operations are evaluated left to right, whereas others are evaluated right to left. The<br />

following list shows the operators of bc from highest precedence to lowest.<br />

bc Operator Associativity<br />

( ) Left to right<br />

Unary ++ −− Not applicable<br />

Unary − ! Not applicable<br />

^ Right to left<br />

* / % Left to right<br />

+ − Left to right<br />

= ^= *= /= %= +=<br />

Right to left<br />

== = != < ><br />

None<br />

&& Left to right<br />

|| Left to right<br />

bc’s order of precedence is not the same as C’s. In C, the assignment operators<br />

have the lowest precedence.<br />

The following list describes what each operation does. In the descriptions, A and B<br />

can be numbers, variables, array elements, or other expressions. V must be either a<br />

variable or an array element.<br />

(A) Indicates that this expression—A—should be evaluated before any other<br />

operations are performed on it.<br />

-A Is the negation of the expression.<br />

!A Is the logical complement of the expression. If A evaluates to zero, !A<br />

evaluates to 1. If A is not zero, !A evaluates to zero. This operator is unique<br />

to this version of bc.<br />

++V Adds 1 to the value of V. The result of the expression is the new value of V.<br />

− −V Subtracts 1 from the value of V. The result of the expression is the new<br />

value of V.<br />

V++ Adds 1 to the value of V, but the result of the expression is the old value of<br />

V.<br />

V− − Subtracts 1 from the value of V, but the result of the expression is the old<br />

value of V.<br />

A ^ B Calculates A to the power B. B must be an integer. The scale of the result of<br />

A^B is:<br />

54 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!