Is there a simple way to check a C++ code in a debugger for the very first appearance of a NaN value?
NaN, an acronym for Not a Number is an exception that usually occurs in the cases when an expression results in a number that is undefined or can't be represented. It is used for floating-point operations. For example: The square root of negative numbers.
Stepping Over a Function on the Debug toolbar or select Debug:Step Over. The debugger executes the function call and then pauses after the function returns. In addition, you can user hotkey: Alt+Num* quickly locate to the current execution point.
The answer is given here: https://stackoverflow.com/a/5394095/1326595
Just include
#include <fenv.h>
and than add the following line to the code:
feenableexcept(FE_INVALID | FE_OVERFLOW);
The debugger is than able to capture the signal and shows the very first occurrence of a NaN.
By IEEE standard the following condition is false
for NaN
's:
val == val
and you could use it to trigger assert or software breakpoint, but beware of compiler optimizations. Probably, in debug build it would not get optimized away
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With