From: joerg@wilma.physik.uni-stuttgart.de (Joerg Stadler)
Subject: Fortran is strange on DEC Alpha
Date: 04 Jan 1995 08:34:49 GMT [thread overview]
Message-ID: <JOERG.95Jan4093450@wilma.physik.uni-stuttgart.de> (raw)
Hello everybody,
we stumbeled over this piece of fortran-code yesterday
program another_bug
i=256
print *, (2*i-1)*4194304
end
When compiled with f77 and default options, this works as expected.
BUT, when I use f77 -check overflow it aborts:
>f77 -check overflow t.f
>a.out
forrtl: error: floating point exception
IOT trap (core dumped)
>
According to the manpage -check overflow generates traps on interger
overflows.
Now, this behavior is STRANGE (at least to me) because
first, the above program only does INTEGER calculations but the system
reports a FLOATING point exception.
second, the above expression DOES NOT RESULT in an overflow. The expession
(2*256 - 1)*4194304 (a)
can be written as
(2**8 - 1) * 2**22 (b)
which is LESS than 2**31. Maybe the compiler evaluates it as
2**8 * 2**22 - 2**22 (c)
That would explain trap (but not the floating exception errormessage).
My question ist: Is the compiler free to do such transformations as
from (a) to (c), which are mathematically (but not numerically)
equivalent? If so, is there a way to stop it? Or at least a way of
knowing which transformations where applied (i.e. a way to find out
whats going on :-) ).
BTW, this discussion is based on the assumption of 32bit integers, we
are running on OSF1 V3.0 347 alpha and DEC Fortran V3.5-576.
Any ideas?
Thanks
joerg
--
J"org Stadler joerg@itap.physik.uni-stuttgart.de
Inst. f. Theoretische und Angewandte Physik Phone: 0711 / 685 - 5268
Universit"at Stuttgart Pfaffenwaldring 57 Room 6.346
70550 Stuttgart
next reply other threads:[~1995-01-04 8:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-01-04 8:34 Joerg Stadler [this message]
1995-01-04 16:17 ` Fortran is strange on DEC Alpha Steve Lionel
1995-01-05 2:09 ` John Hascall
1995-01-05 9:15 ` Joerg Stadler
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox