Double.IsNaN(Double) 方法

定義

傳回值,這個值表示指定的值是否不是數字 (NaN)。Returns a value that indicates whether the specified value is not a number (NaN).

public:
 static bool IsNaN(double d);
public static bool IsNaN (double d);
static member IsNaN : double -> bool
Public Shared Function IsNaN (d As Double) As Boolean

參數

d
Double

雙精確度浮點數。A double-precision floating-point number.

傳回

如果 d 計算結果為 NaN,則為 true;否則為 falsetrue if d evaluates to NaN; otherwise, false.

範例

下列程式碼範例說明如何使用 IsNaNThe following code example illustrates the use of IsNaN:

// This will return true.
if ( Double::IsNaN( 0 / zero ) )
{
   Console::WriteLine( "Double::IsNan() can determine whether a value is not-a-number." );
}
// This will return true.
if (Double.IsNaN(0 / zero)) 
   Console.WriteLine("Double.IsNan() can determine whether a value is not-a-number.");
' This will return true.
If Double.IsNaN(0 / zero) Then
    Console.WriteLine("Double.IsNan() can determine whether a value is not-a-number.")
End If

備註

浮點作業會傳回 NaN,以表示作業的結果未定義。Floating-point operations return NaN to signal that result of the operation is undefined. 例如,將0.0 除以0.0 會產生 NaNFor example, dividing 0.0 by 0.0 results in NaN.

注意

如果 DoublePositiveInfinityNegativeInfinityIsNaN 會傳回 falseIsNaN returns false if a Double value is either PositiveInfinity or NegativeInfinity. 若要測試這些值,請使用 IsInfinityIsPositiveInfinityIsNegativeInfinity 方法。To test for these values, use the IsInfinity, IsPositiveInfinity, and IsNegativeInfinity methods.

適用於

另請參閱