007. Integer division truncates#
topic: Basics
print *, 2+3, 2-3, 2*3, 2/3, 2/3.0, 2.0/3, 2**3
end
5 -1 6 0 0.666666687 0.666666687 8
2/3 = 0 in Fortran because the quotient of two integers is truncated to an integer. The quotient of an integer and a real is a real.
print*,2+3,2-3,2*3,2/3,2/3.0,2.0/3,2**3
— FortranTip (@fortrantip) December 17, 2021
gives
5 -1 6 0 0.6666667 0.6666667 8
2/3 = 0 in Fortran because the quotient of two integers is truncated to an integer. The quotient of an integer and a real is a real.
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags