From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,460d73061f822e6 X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1995-01-04 23:49:22 PST Path: nntp.gmd.de!Germany.EU.net!news.dfn.de!news.belwue.de!news.uni-stuttgart.de!newS.uni-stuttgart.de!joerg From: joerg@wilma.physik.uni-stuttgart.de (Joerg Stadler) Newsgroups: comp.unix.osf.osf1 Subject: Fortran is strange on DEC Alpha Date: 04 Jan 1995 08:34:49 GMT Organization: ITAP Uni Stuttgart Distribution: world Message-ID: Reply-To: joerg.stadler@itap.physik.uni-stuttgart.de NNTP-Posting-Host: wilma.itap.physik.uni-stuttgart.de 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