next up previous contents index
Next: Restrictions Up: Arithmetic Expressions Previous: Data Type Conversions

Integer Division

 

Integer division always produces a result which is another integer value: any fractional part is truncated, i.e. rounded towards zero. This makes it especially important to provide a decimal point at the end of a real constant even if the fractional part is zero. For example:

8 / 3 $\Longrightarrow$ 2 -8 / 3 $\Longrightarrow$ -2 2**(-3) $\Longrightarrow$ 1/(2**3) $\Longrightarrow$ 1/8 $\Longrightarrow$ 0

The combination of the two preceding rules may have unexpected effects, for example:

(-2)**3 $\Longrightarrow$ -2 * -2 * -2 $\Longrightarrow$ -8
whereas (-2)**3.0 is an invalid expression as the computer would try to evaluate the logarithm of -2.0, which does not exist. Similarly, the expression:
3 / 4 * 5.0 $\Longrightarrow$ REAL(3/4) * 5.0 $\Longrightarrow$ 0.0
whereas
5.0 * 3 / 4 $\Longrightarrow$ 15.0 / REAL(4) $\Longrightarrow$ 3.75



Helen Rowlands
8/27/1998