PDA

View Full Version : In Linux round() NAN float, return negative garbage values



npatil15
29th January 2020, 05:35
Hello,

I'm trying to do something like below,


float realValue = 5.2;
float nanValue = NAN;
qDebug()<<"realValue"<<round(realValue)<<"nanValue"<<round(nanValue);

Output in Linux:

realValue 5 nanValue -2147483648

Here for NAN value, it's giving negative value. Is there any alternative for this or how should I handle this in Linux?

I'm using these values to set the size of variable and size cannot be negative nor NAN.

Again, if anyhow I tried to figure out NAN value, then added with NAN value is always NAN.

qDebug()<<"Output is: "<<(NAN+90)
//Output:
Output is: NAN


Thanks :)

Ginsengelf
29th January 2020, 07:55
Hi, not sure what you want to do. If your size cannot be NAN, then why use it?

In C++11 you can check for NAN using isnan() (http://www.cplusplus.com/reference/cmath/isnan/).

Ginsengelf

npatil15
29th January 2020, 08:17
Hi,

Because some time it will be real value not NAN everytime.
And thanks, isnan() will work.