NaN problem

Hello,

I have written a Root program which I compiled thanks to a makefile and so for that I have created a TApplication. I do not know if it is a bug, but I was taking the square root of a negative number in my code (I got no warning during the compilation because this number was randomly generated) and when I run the program I have no segmentation fault or other error even if the number does not exist, in fact if I print it I have only NaN, and so I can multiply this number without error, I find this behaviour strange…

Best regards,

Pierre-Louis

Hi,

there’s nothing specially ROOT related about that. See e.g. en.wikipedia.org/wiki/NaN#How_is … created.3F

My ROOT App is about people presenting their applications, not about support requests. I’ll move the posting.

Axel.

Hello,

I read the webpage, and I tried to compile a little C++ code with sqrt(-4) and in fact I got no error, I was thinking I should have one, sorry.

Best regards,

Pierre-Louis

[quote=“ppernet”]… even if the number does not exis[/quote]You are not correct. The NaN number DOES exist. :bulb: [quote=“ppernet”] I have only NaN, and so I can multiply this number without error, I find this behaviour strange…
[/quote]This is the correct behavior as soon as the NaN exception is suppressed. NaN is a special number the CPU can operate with (re-read the Wikipedia link posted by Axel)
By definition:

[quote=“ppernet”]. . .I tried to compile a little C++ code with sqrt(-4) and in fact I got no error, I was thinking I should have one. . . [/quote]No, you should not anticipate any error. See root.cern.ch/root/html522/TSyste … SetFPEMask
and its Unix implementation: root.cern.ch/root/html522/src/TU … html#dqE1h
Try[code]root.exe [0] float a = sqrt(-4); // no problem. “a” is assigned a good NaN value
root.exe [1] float b = a * 3; // b is assigned the NaN value too
root.exe [2] gSystem->SetFPEMask(kInvalid | kDivByZero | kOverflow );
root.exe [3] float c = sqrt(-4); // now we are facing the exception

*** Break *** floating point exception
Root >[/code]By the way, en.wikipedia.org/wiki/NaN#NaNs_in_floating_point suggests the trick: [quote]One can therefore test whether a variable has a NaN value by comparing it to itself, thus if x = x gives false then x is a NaN code.[/quote]

Thank you for all this help.

Pierre-Louis