Re: [ROOT] TMath::Nint

From: Martin Veselsky (martin@orion1.tamu.edu)
Date: Mon Nov 27 2000 - 21:06:21 MET


George Heintzelman wrote:

> > root [315] TMath::Nint(0.50)
> > (Int_t)0
> > root [316] TMath::Nint(1.50)
> > (Int_t)2
> > root [317] TMath::Nint(2.50)
> > (Int_t)2
> > root [318] TMath::Nint(3.50)
> > (Int_t)4
> > root [319] TMath::Nint(4.50)
> > (Int_t)4
> > root [320] TMath::Nint(5.50)
> > (Int_t)6
> > root [321] TMath::Nint(6.50)
> > (Int_t)6
> > root [322]
> >
> > May be the problem is in the representation of floats.
> > I tried also double precision with the same result.
> > In any case it would be fine to have regular behavior
> > with rounding either up or down.
>
> This is a regular behavior, known as the 'banker's round' -- round
> half-integers to the nearest even number. Otherwise the rounding does
> not preserve averages when applied to data sets with quantized values
> including exactly half-integral numbers.
>
> However I would think having some documentation on this in TMath::Nint
> would be useful.
>

I just checked the behavior of nint() in g77 and it does NOT obey the
above rule.
On the other hand the C intrinsic rint() does. If employing fortran name
( what is the case ) it would make sense to preserve also fortran
behavior.
For those who like rint let's make TMath:Rint and avoid confusion.
In any case I agree that good documentation usually helps.
with best regards
martin

>
> George Heintzelman
> gah@bnl.gov



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:38 MET