31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

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.

EXPRESSIONS<br />

Table 3-1:<br />

Arithmetic Operators<br />

Operator<br />

Example<br />

Meaning<br />

--------------------------<br />

+ A+B<br />

A-B<br />

* A*B<br />

** A**B<br />

Add l\ and B<br />

Subtract B from A<br />

Multiply A by B<br />

Ra ise A to the power of B<br />

I<br />

AlB<br />

Divide A by B<br />

DIV<br />

A DIV B<br />

Divide A<br />

by B and truncate the result<br />

MOD<br />

A MOD B<br />

Produce the remainder after dividing A by<br />

B; B must be greater than 0<br />

The addition, subtraction, muJtiplication, and exponentiation (+, ,<br />

*, and **) operators work on both integer and real values. They<br />

produce real results when applied to real values and integer results<br />

when applied to integer values. If the expression contains values of<br />

both types, the result is a real number. The only exception to these<br />

rules concerns exponentiation. <strong>PASCAL</strong> defines the results of an<br />

integer raised to the power of a negative integer as follows:<br />

Base<br />

Exponen t<br />

Result<br />

0 Negative or 0<br />

1 Negative<br />

-1 Negative and odd<br />

-1 Negative and even<br />

Any o the r<br />

integer<br />

Negative<br />

For example, the expression 1**(-3) equals 1;<br />

(-1)**(-4) equals 1; and 3**(-3) equals o.<br />

Error<br />

1<br />

-1<br />

1<br />

(-1)**{-3) equals -1;<br />

o<br />

The division (I) operator can be used on both real and integer values,<br />

but always produces a real result. Use of the division (I) operator<br />

can therefore cause errors in precision in expressions involving<br />

integers.<br />

The DIV, MOD, and REM operators apply to integer values only.<br />

DIV divides one integer by another, producing an integer result. DIV<br />

truncates the result; that is, it drops any fraction. It does not<br />

round the result. For example, the expression 23 DIV 12 equals 1, and<br />

(-5) DIV 3 equals -1.<br />

The MOD and REM operators return the remainder after dividing one<br />

operand by another. Both operators can be used only with integer<br />

values and always produce integer results.<br />

The MOD operator can be used only when the divisor is greater than 0;<br />

it always returns a positive result. For example, the expression 5<br />

MOD 3 (5 modulo 3) returns a value of 2, and (-5) MOD 3 returns a<br />

value of 1.<br />

3-2

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

Saved successfully!

Ooh no, something went wrong!