# NaN

Need to verify if a float is NaN but I can’t find any support for this in GHI lib.

Any ide how I can test if a float is NaN?

``````public const float NaN = 0.0f / 0.0f;
public const float NegativeInfinity = -1.0f / 0.0f;
public const float PositiveInfinity = 1.0f / 0.0f;
``````

Then check against those?

It would help if you told us why you need to do this.

If I read an array of bytes from flash and convert it to a float it will get NaN, this becaus I haven’t stored any valid data in flash at that position.

And if I use the loaded float in a math operation I get an exception, so I need to check if the float is a valid number befor calculation.

Check the byte before conversion if its a valid float format byte?

If you look up the datasheet for the chipset, it should mention what floating point format it’s using - then look up the definition for that format.

This method always returns true?!?! If I debug and hovers the mouse over “f != NaN” it say true when f = 1.2 which is ok. But when stepping it doesn’t care about that.

``````
public static bool IsNaN(float f)
{
bool retValue = false;

if (f != NaN)
retValue = false;
else if (f == NaN)
retValue = true;

return retValue;
}

``````

Could you post the whole code please?

I’m confused… Why isn’t the standard .Float.NaN from .NET included in .NETMF?

This will be a Microsoft team question www.netmf.com but we are trying to see if we can help you achieve what you need.

``````
byte[] buffer = new byte[InternalFlashStorage.Size];
float tmp;

if (rdBoost.Tools.IsNaN(tmp))
tmp = 1.8F;
ValveControl.Instance.Kp = tmp;

``````

Maybe this helps. Don’t know what became of it.
http://www.tinyclr.com/forum/2/3590/

Somebody else was asking the original question. I just stuck my head in, wondering if anybody knew why Float.NaN wasn’t included in .NETMF.

I assumed that .NETMF was, from a user point of view, pretty hardware agnostic on areas like this. Does this (and, say, things like Int32.MaxValue) vary on different platforms?

Maybe compiler didn’t support it, maybe forgot about it, maybe they saw it not needed? The NETMF team is responsive and more than happy to help and and answer questions so someone can always check with them