Whenever NaN is returned, I would like for the value returned to instead be 0. What is the best way to go about achieving this end?
Asked
Active
Viewed 156 times
1
-
Can you explain more of the context you need to do this? It's too open-ended right now. – Mysticial Jan 17 '13 at 02:25
-
2relevant http://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c – Aziz Jan 17 '13 at 02:26
-
Curious: Wasn't @Pavan solution an acceptable one? – chux - Reinstate Monica Aug 05 '13 at 18:24
1 Answers
7
You can use this function
float zero_nan(float n)
{
return n == n ? n : 0;
}
you can inline the function and wrap any return values you think may be nans.

Pavan Yalamanchili
- 12,021
- 2
- 35
- 55