[PATCH][4.3] Expand lround inline for x86_64/i?86 SSE math

Steve Kargl sgk@troutmask.apl.washington.edu
Thu Oct 19 23:25:00 GMT 2006


On Thu, Oct 19, 2006 at 03:34:23PM -0700, Steve Kargl wrote:
> 
> It states that NINT(X) = INT(X+0.5) for X > 0.  You then
> find INT(A) = 0 for |A| < 1.  A quick scan over the section
> on numeric binary operators did not reveal the normal 
> weasel words, but I suspect that the result of X+0.5 is a
> processor-dependent approximation and round-to-nearest
> meets that criterium.
> 
> OTOH, I think it is a bug because we can choose a better
> algorithm to determine if x+0.5 is truly less than 1.
> See for example round[f] in intrinsics/c99_functions.c
> 

Upon further review, the standard says NINT(X) = INT(X+0.5)
for X > 0.  So, if and when someone makes a change to the
inlining of NINT(X), its result needs to agree with
INT(X+0.5).  

troutmask:kargl[208] cat f.f90
    program nint_bug
      real :: x
      x = nearest(0.5, -1.)
      if (x < 0.5) then 
         write(*,*) x + 0.5, nint(x), int(x+0.5)
      end if
    end program
troutmask:kargl[209] gfc -o z f.f90
troutmask:kargl[210] ./z
   1.000000               1           1

For the record the standard says

  1.4    Exclusions
  This standard does not specify
      (6)  The physical properties of the representation of quantities
           and the method of rounding, approximating, or computing
           numeric values on a particular processor,



-- 
Steve



More information about the Fortran mailing list