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);
Parameter:
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.
Example:
Input : d = 0.0 / 0.0
Output : True
Input : d = 1.734
Output : False
Code: To demonstrate the Double.IsNaN(Double) method.
using System;
class GFG {
public static void Main(String[] args)
{
Double f1 = 1.0 / 0.0;
bool res = Double.IsNaN(f1);
if (res)
Console.WriteLine(f1 + " is NaN" );
else
Console.WriteLine(f1 + " is not NaN" );
double f2 = 0.0 / 0.0;
bool res1 = Double.IsNaN(f2);
if (res1)
Console.WriteLine(f2 + " is NaN" );
else
Console.WriteLine(f2 + " is not NaN" );
}
}
|
Output:
Infinity is not NaN
NaN is NaN
Note:
- 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.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...