C# Single NaN
Description
Single NaN
represents not a number (NaN). This field is
constant.
Syntax
Single.NaN
has the following syntax.
public const float NaN
Example
// w ww. j ava2 s .com
using System;
public class MainClass{
public static void Main(String[] argv){
float zero = 0.0f;
Console.WriteLine("{0} / {1} = {2}", zero, zero, zero/zero);
float nan1 = Single.NaN;
Console.WriteLine("{0} + {1} = {2}", 3, nan1, 3 + nan1);
Console.WriteLine("Abs({0}) = {1}", nan1, Math.Abs(nan1));
float result = Single.NaN;
Console.WriteLine("{0} = Single.NaN: {1}",
result, result == Single.NaN);
zero = 0;
// This condition will return false.
if ((0 / zero) == Single.NaN)
{
Console.WriteLine("0 / 0 can be tested with Single.NaN.");
}
else
{
Console.WriteLine("0 / 0 cannot be tested with Single.NaN; use Single.IsNan() instead.");
}
}
}
The code above generates the following result.