Main Site Documentation

NaN


#1

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?


#2

Add this to your code?

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.


#3

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.


#4

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.


#5

#6

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;
        }


#7

Test on emulator please


#8

Could you post the whole code please?


#9

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


#10

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.


#11

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

            InternalFlashStorage.Read(buffer);

            GHIElectronics.NETMF.System.Util.ExtractValueFromArray(out tmp, buffer, (int)Enum.ConfigAddress.ValveKpParameter);
            if (rdBoost.Tools.IsNaN(tmp))
                tmp = 1.8F;
            ValveControl.Instance.Kp = tmp;


#12

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


#13

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?


#14

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 :slight_smile: