INT(x) == 1 if x < 1?
Daniel Franke
franke.daniel@gmail.com
Sun Oct 29 22:37:00 GMT 2006
Hi all,
as the subject indicates, this is somewhat strange. Also I am aware that
finite length binary representation of rational numbers is only an
approximation, I was caught flat footed when my program segfaulted due to an
issue similar to this:
$> cat int.f90
program test_int
WRITE(*,*) INT(0.9999999)
WRITE(*,*) INT(0.99999999)
END PROGRAM
$> gfortran int.f90
$> ./a.out
0
1
INT(x) is supposed to return 0 if x < 0 [1], a requirement obviously satisfied
by x = 0.99999999 (at least to a human reader).
Is there something wrong with the implementation of INT() or do I have to add
yet another layer of precaution when dealing with real numbers?
Daniel
[1] http://gcc.gnu.org/onlinedocs/gfortran/INT.html
More information about the Fortran
mailing list