RE: TMath::Nint

Valery Fine (fine@bnl.gov)
Thu, 29 Apr 1999 11:14:17 -0400


>
> Hi,
> I try, and try, and try, ... to understand what the TMath::Nint function
> does, but I can't. I have the feeling that someone tries to swindle me.
> Any help appreciated,
> Jacek.
>

inline Int_t TMath::Nint(Float_t x)
{
int i = int(x + 0.5);
if (x + 0.5 == Float_t(i) && i & 1) i--;
return i;
}

This makes sense if one wants to count something essential
(like money for example). The rounding rule getting the biggest value
when x - [x] == 0.5 exactly causes the systematical error. The present
approach allows eliminate that systematical error by shifting it into
opposite directions between odd and even numbers.

I hope you feel better yourself now.
Valery