This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug fortran/15205] New: NEAREST intrinsic returns wrong value in DOUBLE PRECISION


The NEAREST intrinsic for DOUBLE PRECISION kind type is returning the
wrong value.  Consider the following program:

  program test_nearest

  implicit none

  real(4) sr, sx, ss
  real(8) dr, dx, ds

  sx = 1.237e0_sp
  ss = 1.e0_sp
  sr = nearest(sx,ss)
  write(*,1) 'nearest(', sx, ',', ss, ') = ', sr
1 format(a,e15.8,a,e15.8,a,e15.8)
  ss = -1.e0_sp
  sr = nearest(sx,ss)
  write(*,1) 'nearest(', sx, ',', ss, ') = ', sr

  dx = 1.237e0_dp
  ds = 1.e0_dp
  dr = nearest(dx,ds)
  write(*,2) 'nearest(', dx, ',', ds, ') = ', dr
2 format(a,e23.16,a,e23.16,a,e23.16)
  ds = -1.e0_dp
  dr = nearest(dx,ds)
  write(*,2) 'nearest(', dx, ',', ds, ') = ', dr

end program test_nearest

Gfortran yields

kargl[328] ./nearest
nearest( 0.12369999E+01, 1.00000000E+00) =  0.12370001E+01
nearest( 0.12369999E+01,-1.00000000E+00) =  0.12369998E+01
nearest( 0.1237000000000000E+01, 1.0000000000000000E+00) = -0.4303249471964870E-36
nearest( 0.1237000000000000E+01,-1.0000000000000000E+00) = -0.4303249471964870E-36

NAG's compiler gives

nearest( 0.12370000E+01, 0.10000000E+01) =  0.12370001E+01
nearest( 0.12370000E+01,-0.10000000E+01) =  0.12369999E+01
nearest( 0.1237000000000000E+01, 0.1000000000000000E+01) =  0.1237000000000000E+01
nearest( 0.1237000000000000E+01,-0.1000000000000000E+01) =  0.1237000000000000E+01

Environment:
System: FreeBSD c-67-168-59-70.client.comcast.net 5.2-CURRENT FreeBSD 5.2-CURRENT #2: Sat Apr 24 10:33:08 PDT 2004 kargl@c-67-168-59-70.client.comcast.net:/usr/obj/usr/src/sys/HOTRATS i386


	
host: i386-unknown-freebsd5.2
build: i386-unknown-freebsd5.2
target: i386-unknown-freebsd5.2
configured with: ../gcc/configure --prefix=/home/kargl/gcc/work --disable-libmudflap --enable-languages=c,f95 --with-gmp=/usr/local

How-To-Repeat:
	See above.

-- 
           Summary: NEAREST intrinsic returns wrong value in DOUBLE
                    PRECISION
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kargl at c-67-168-59-70 dot client dot comcast dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-unknown-freebsd5.2
  GCC host triplet: i386-unknown-freebsd5.2
GCC target triplet: i386-unknown-freebsd5.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15205


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