Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Single.NaN Field

Represents not a number (NaN). This field is constant.

[Visual Basic]
Public Const NaN As Single
[C#]
public const float NaN;
[C++]
public: const float NaN;
[JScript]
public var NaN : float;

Remarks

The value of this constant is the result of dividing zero by zero.

This constant is returned when the result of an operation is undefined.

Use IsNaN to determine whether a value is not a number. It is not possible to determine whether a value is not a number by comparing it to another value equal to NaN.

Example

[Visual Basic, C#, C++] The following sample demonstrates the NaN constant.

[Visual Basic] 
Dim zero As Single = 0

' This condition will return false.
If (0 / zero) = Single.NaN Then
    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.")
End If

[C#] 
Single 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.");
}

[C++] 
Single zero = 0;

// This condition will return false.
if ((0 / zero) == Single::NaN) {
   Console::WriteLine(S"0 / 0 can be tested with Single::NaN.");
} else {
   Console::WriteLine(S"0 / 0 cannot be tested with Single::NaN; use Single::IsNan() instead.");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Single Structure | Single Members | System Namespace | IsNaN

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.