Check Not-a-Number

To test if a float-point value is a NaN(Not a Number), use the method from float or double.


using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(double.IsNaN(0.0 / 0.0));  // True

    }
}

The output:


True

We can also use the object.Equals to compare two NaN values.


using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(object.Equals(0.0 / 0.0, double.NaN));  // True

    }
}

The output:


True
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.