Need to pass some data back and forth bewteen matlab and some DLL functions, one thing stand out there is that we dont know the exact numeric value of NaN in matlab, so there will be some unnecessary data processing to take these values into account.
Do anyone know the exact values or at least the ranges of values for NaN in matlab?
I am most interested in knowing the following two primative types:
(1) NaN for float (32);
(2) NaN for double (64).
According to Mathwork’s documentation,
NaNreturns the IEEE arithmetic representation for Not-a-Number. NaN is always in floating point representation (float or double) – I don’t believe there is an integer NaN.In IEEE 754, NaN’s are represented as floating point numbers with all the exponent bits set to 1 and the fractional part any non-zero value (so there are actually many ways of representing a general NaN). See “Special Values” here.
The most reliable way to test for NaN by hand is not to look for a specific value but to test that all the exponent bits are set and the fractional part is non-zero.