To find the cause of floating point variables beeing set to NaN in my C++ program I enabled floating point exceptions like this:
#include <fenv.h>
feenableexcept(FE_INVALID | FE_OVERFLOW);
I know it works because when I write:
int val = 0.0/0.0;
in my program a floating point exception is risen. But NaNs are "spreading" through the floating point calculations of my program and I have no idea which variable is set to NaN first.
What causes for a variable beeing set to NaN exist, that would not cause a floating point exception?
isNaN
function and start littering your code withassert(!isNaN(x))
– Mopeinf
s and0
s, which can quickly lead toNaN
s. – Neigh