Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Double.IsNaN() Method in C#

  • Last Updated : 13 Feb, 2019

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
Recommended Articles
Page :