This is the mail archive of the gcc-patches@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]

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


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


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