Re: nan/inf behaviour in ROOT

From: Konstantin Olchanski <olchansk_at_triumf.ca>
Date: Thu, 11 Mar 2010 09:42:10 -0800


On Thu, Mar 11, 2010 at 09:51:35AM +0100, Vito Di Benedetto wrote:
> If I type the following instruction
>
> root [0] Float_t a = 0.
> root [1] Float_t b = 10.
> root [2] b/a
> (double)inf
> root [3] Float_t c = -10.
> root [4] TMath::Sqrt(c)
> (const double)nan
>
> I don't get exception. I have just inf or nan.

This is the normal floating point math as defined by IEEE-754/854.

To test and prevent "nan" and "inf" values from propagating too far through computations, one can use functions "isnan" & co (man isnan), or you can enable the floating point exceptions as noted by other replies.

One thing to keep in mind is performance cost implications - processing FPU exceptions is quite time consuming while "inf" and "nan" algebra is probably implemented in the FPU hardware and I would expect it to be faster.

-- 
Konstantin Olchanski
Data Acquisition Systems: The Bytes Must Flow!
Email: olchansk-at-triumf-dot-ca
Snail mail: 4004 Wesbrook Mall, TRIUMF, Vancouver, B.C., V6T 2A3, Canada
Received on Thu Mar 11 2010 - 18:42:24 CET

This archive was generated by hypermail 2.2.0 : Thu Mar 11 2010 - 23:50:01 CET