# double, NaN, and super small numbers

• 08-17-2007
nbo10
double, NaN, and super small numbers
Hi All,
I need a quick answer, I have a function that returns a double, the formula becomes super small and eventually becomes less tan 10^-308, and then it returns NaN instead of 0, Once my function is ~10^-10 for my purposes is zero, How do I get it to return 0 if it's less than a certain value or if it is NaN I would like to to return 0. Thanks
• 08-17-2007
pianorain
Quote:

Originally Posted by nbo10
Hi All,
I need a quick answer, I have a function that returns a double, the formula becomes super small and eventually becomes less tan 10^-308, and then it returns NaN instead of 0, Once my function is ~10^-10 for my purposes is zero, How do I get it to return 0 if it's less than a certain value or if it is NaN I would like to to return 0. Thanks

Just a little bit of rewording:
Code:

```if (function value is less than 'certain value') or (function value is NaN)   return 0; return function value;```
I mean, by asking the question, you've practically got the pseudo-code for it.
• 08-17-2007
nbo10
So how would I code to check if a double is NaN?
• 08-17-2007
matsp
Code:

```float x; isnan(x); or in microsoft compiler: _isnan(x);```
--
Mats
• 08-17-2007
nbo10
Thanks I was trying x=='NaN' and it wasn't working.

isnan works great. thanks
• 08-17-2007
iMalc
I believe you can also use other tests like if (!(x==x)) to check for nans.