This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bug in NINT() in gfortran


On 6/12/2010 12:07 AM, Hans Jørgen Aagaard Jensen wrote:
The NINT() intrinsic in current gfortran under cygwin has a bug. Below follows:
1) small test program
2) output from this program
3) output from "gfortran -v"

(I am not submitting this to the gcc bugzilla, because the test worked OK on all the linux systems I tested.)
(I found the error becaus our quantum chemistry softward dirac (http://dirac.chem.sdu.dk) failed a few of the internal tests.)

-- Hans Jørgen Aa. Jensen

======= 1) small test program ============
       program test
       double precision xval
       xval = 132843.61283756854D0
       do i = 1,7
          ipoint = nint(xval)
          write (6,*), xval, ipoint
          xval = 10.0d0*xval
       end do
       return
       end
======= 1) output =============
    132843.61283756854           132844
    1328436.1283756853      -1596096578


Try the following replacement for nint():
ipoint = xval+.5
which leads me to believe the lround function from newlib is buggy.
If you wished to handle negative as well as positive, the work-around
ipoint = xval+sign(.5,xval)
would take it a little further. This short-cuts the distinction between ieee_nearest and legacy Fortran rounding style, but I don't see that gfortran was making the distinction.


--
Tim Prince


-- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]