Re: [ROOT] TMath::Nint

From: George Heintzelman (gah@bnl.gov)
Date: Mon Nov 27 2000 - 21:13:54 MET


> 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.

George Heintzelman
gah@bnl.gov



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