Single.IsNaN() Method in C# with Examples
In C#, Single.IsNaN(Single) is a Single struct method. This method is used to check whether the specified floating-point value is not a number (NaN).
Syntax: public static bool IsNaN (float f);
Parameter:
f: It is a single-precision floating-point number of type System.Single.
Return Type: This function returns a boolean value i.e. True, if specified value is not a number(NaN), otherwise returns False.
Example:
// C# program to demonstrate // Single.IsNaN(Single) method using System; class GFG { // Main Method public static void Main(String[] args) { // first example float f1 = 1.0f / 0.0f; bool res = Single.IsNaN(f1); // printing the output if (res) Console.WriteLine(f1 + " is NaN" ); else Console.WriteLine(f1 + " is not NaN" ); // second example // it will give result // NaN float f2 = 0.0f / 0.0f; bool res1 = Single.IsNaN(f2); // printing the output if (res1) Console.WriteLine(f2 + " is NaN" ); else Console.WriteLine(f2 + " is not NaN" ); } } |
Infinity is not NaN NaN is NaN
Note:
- This method returns false if a Single value is either PositiveInfinity or NegativeInfinity.
- Floating point operation returns a NaN to show that the result of the operation is undefined.
Reference:
Recommended Posts:
- MathF.Log() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Cos() Method in C# with Examples
- MathF.Exp() Method in C# with Examples
- MathF.Min() Method in C# with Examples
- MathF.Max() Method in C# with Examples
- MathF.Abs() Method in C# with Examples
- MathF.Pow() Method in C# with Examples
- MathF.Tan() Method in C# with Examples
- UInt32.ToString Method in C# with Examples | Set - 2
- UInt16.ToString Method in C# with Examples | Set - 2
- C# | Char.GetHashCode() Method with Examples
- C# | Char.GetTypeCode() Method with Examples
- UInt64.ToString() Method in C# with Examples | Set - 1
- UInt64.ToString Method in C# with Examples | Set - 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.