Double.IsNaN() Method in C#

In C#, Double.IsNaN() is a Double struct method. This method is used to check whether the specified value is not a number (NaN).

Syntax: public static bool IsNaN (double d);

d: It is a double-precision floating-point number of type System.Double

Return Type: This function returns a Boolean value i.e. True, if specified value is not a number(NaN), otherwise returns False.


Input  : d = 0.0 / 0.0 
Output : True

Input  : d = 1.734
Output : False

Code: To demonstrate the Double.IsNaN(Double) method.





// C# code to demonstrate 
// Double.IsNaN(Double) method 
using System;
class GFG { 
    // Main Method
    public static void Main(String[] args) 
        // first example 
        Double f1 = 1.0 / 0.0; 
        bool res = Double.IsNaN(f1); 
        // printing the output 
        if (res) 
            Console.WriteLine(f1 + " is NaN"); 
            Console.WriteLine(f1 + " is not NaN"); 
        // second example 
        double f2 = 0.0 / 0.0; 
        bool res1 = Double.IsNaN(f2); 
        // printing the output 
        if (res1) 
            Console.WriteLine(f2 + " is NaN"); 
            Console.WriteLine(f2 + " is not NaN"); 



Infinity is not NaN
NaN is NaN


  • If we divide any value by 0 directly, the Compiler will show an error. So, in the above example, 0 is stored in a variable first.
  • Every floating point operation returns a NaN to show that the result of the operation is undefined.

My Personal Notes arrow_drop_up

self motivated and passionate programmer

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.