This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
read float into integer
- From: pkienzle <pkienzle at gmail dot com>
- To: fortran at gcc dot gnu dot org
- Date: Wed, 29 Aug 2007 13:05:55 -0700 (PDT)
- Subject: read float into integer
I don't know if it is a bug, but gfortran does not truncate floating point
values toward 0 on input. The f90 code I'm trying to compile assumes that
it does.
Here's a small test program to demonstrate the issue:
integer(4) :: n
logical :: b
read (*,*,err=20) n,b
write (*,*) n,b
stop
20 write (*,*) 'Couldn''t read integer.'
end
Here is the comparison between Intel Fortran and gfortran on OS X:
$ifort io.f90
$echo 2 T | ./a.out
2 T
$echo 2.9 T | ./a.out
2 T
$echo 2.900e3 T | ./a.out
2900 T
$echo -2.9 T | ./a.out
-2 T
$gfortran io.f90
$echo 2 T | ./a.out
2 T
$echo 2.9 T | ./a.out
Couldn't read integer.
$echo 2.900e3 T | ./a.out
Couldn't read integer.
$echo -2.9 T | ./a.out
Couldn't read integer.
--
View this message in context: http://www.nabble.com/read-float-into-integer-tf4350081.html#a12394785
Sent from the gcc - fortran mailing list archive at Nabble.com.