How to check for NaN

Hi there,

I’m using C# and am using some quaternions in one of my scripts. Every so often I receive a debug message saying that some of one of my objects rotation values are Nan, or ‘Not a Number’ (likely because under certain circumstances the square root of a negative number is being calculated / something is being divided by 0).

In any event, I want to perform a check to see if the value will be NaN before altering the object’s rotation. Something like:

if(rotation == Nan)…

or

if(rotation == error)…

Is there such a way to do this?
All I could find was this link, but I can’t find a C# equivalent: http://answers.unity3d.com/questions/182209/Checking-for-quaternion-values-to-not-be-NaN.html

The .NET framework already provides simple ways to achieve this. You can use the constant float.NaN if you need to actually generate a NaN in code, and float.IsNaN(value) returns true if the value is a NaN.

There are some related things, such as constants and comparisons for infinity.

Well, i know this is a old post but, i will help others with simple soluction for check if “float variable” is a NaN or not.

if(float.IsNaN("YOURFLOATVARIABLE")){
      //Your condition...
}
else{
      //Your "else" condition
}

if(!System.Single.IsNaN( someVariable ))
// assign value

can someone explain me ,why (float.NaN == float.NaN) is false ???