I'm working in an environment with a mostly absent double/Math library (NETMF). I wrote this class to make things easier:
public struct DoubleEx
{
public const double NaN = 0.0d / 0.0d;
public static bool IsNaN(double x)
{
return x != x;
}
...
}
Seems like it should work, right?
Well, when I run this code:
Debug.Print("Method call: " + DoubleEx.IsNaN(DoubleEx.NaN));
Debug.Print("Method call: " + DoubleEx.NaN != DoubleEx.NaN);
I get this output:
False
True
Somehow, the act of putting it in a function breaks it! Is there some kind of optimization going on here? Or is the hardware misinterpreting the instructions?