I use Visual C ++ to load binary data into float, for example:
double dValue;
memcpy(&dValue, lpData, sizeof(dValue));
In normal cases, this will work correctly. However, in some rare cases where binary data is corrupted, it dValuewill be invalid and any further operations on it will throw an “Invalid floating-point operation” exception.
I check dValuein the debugger and it displays as -1.#QNAN00000000000.
To prevent the exception, I need to check dValueafter loading it from binary data. I am trying to use:
if (_finite(dValue))
{
… do some tasks…
}
But still invalid dValuewill cause the function to _finiteraise an exception Float-point invalid operation. Although it _finite(dValue)will return 0 correctly, the exception will be highlighted in memory. Even if I free him. Too many allocate / deallocate will run out of system resources anyway.
Therefore, is there a way to determine the validity of a double meaning without any exceptions?
source
share