Next: Intrinsic Procedures
Up: Mixing Objects of Different
Previous: Mixed Type Assignment
If one integer divides another in a subexpression then type of that
subexpression is INTEGER.
Confusion often arises about integer division; in short,
division of two integers produces an integer result by
truncation (towards zero).
Consider,
REAL :: a, b, c, d, e
a = 1999/1000
b = -1999/1000
c = (1999+1)/1000
d = 1999.0/1000
e = 1999/1000.0
- a is (about) 1.000. The integer expression
1999/1000 is evaluated and then truncated
towards zero to produce an integral value, 1. Its says in the Fortran 90
standard, [1], P84 section 7.2.1.1, ``The result of such an operation
[integer division] is the
integer closest to the mathematical quotient and between zero and the
mathematical quotient inclusively.''
- b is (about) -1.000 for the same reasons as above.
- c is (about) 2.000 because, due to the parentheses
2000/1000 is calculated.
- d and e are (about) 1.999 because both RHS's
are evaluated to be real numbers, in 1999.0/1000 and
1999/1000.0 the integers are promoted to real numbers
before the division.
Now try this question
Return to corresponding overview page
Next: Intrinsic Procedures
Up: Mixing Objects of Different
Previous: Mixed Type Assignment
©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997Not for commercial use.