next up previous contents
Next: Assignment Up: Real Numbers Previous: Fractions   Contents

Operators for Real Versus Integer

Both Real and Integer are number types, they share the same notations for addition, subtraction and multiplication. However, they do not share the notation of division.

For Integers, if you want to know the quotient of a division, you use the div operator. For example, in q := dn div dr, variable q receives the quotient of dn divided by dr. For Integer division, you can also receive the remainder of a division using the mod (for modulus) operator. For example in the statement r := dn mod dr, variable r receives the remainder of dn divided by dr.

If you have a Real variable x to receive the result of a division, you use the / operator. For example, in x := 1/3, x receives a value of approximately $0.33333333$.

This practice of using a different operator for real number division from that for integer division is not a standard. In C, C++ and Java, the same operator, /, is used for both. In Visual Basic, however, / is used for real number division, and $\backslash$ is used for integer division.


next up previous contents
Next: Assignment Up: Real Numbers Previous: Fractions   Contents
Tak Auyeung 2003-12-03