questionnable nint() behavior

Timothy C Prince tprince@myrealbox.com
Mon Mar 20 21:43:00 GMT 2006



-----Original Message-----
From: dominiq@lps.ens.fr (Dominique Dhumieres)
To: fortran@gcc.gnu.org
Date: Mon, 20 Mar 2006 22:24:12 +0100
Subject: questionnable nint() behavior

I have found in my file the following program

      program main
      real x, y
      x = 8388609.0
      y = 0.4999999701976776123046875
      print '(A6,F9.1,A3,I8)', 'nint (', x, ') =', nint (x)
      print '(A6,F10.8,A3,I2,A18,L1)', 'nint (', y, ') =', nint (y),    &
     &      ', where y < 0.5 = ', y < 0.5
      end

xlf, ifc, and g95 return

nint (8388609.0) = 8388609
nint (0.49999997) = 0, where y < 0.5 = T

IMHO the correct result, g77, pgf, and gfc return

nint (8388609.0) = 8388610
nint (0.49999997) = 1, where y < 0.5 = T

________________________________--
depends on the options passed to gfortran:

$ gfortran -O -Wall -pedantic dom.f90

$ ./a
nint (8388609.0) = 8388609
nint (0.49999997) = 0, where y < 0.5 = T


I don't know which you are arguing is correct.  Fortran standard clearly requires a different behavior from IEEE round-to-nearest-even.  Are you arguing that gfortran should not change result according to -march ?

Tim Prince



More information about the Fortran mailing list