Single.IsNaN(Single) 方法

定義

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

public:
 static bool IsNaN(float f);
public static bool IsNaN (float f);
static member IsNaN : single -> bool
Public Shared Function IsNaN (f As Single) As Boolean

參數

f
Single

單精確度浮點數。A single-precision floating-point number.

傳回

如果 true 的計算結果為非數值 (f),則為 NaN,否則為 falsetrue if f evaluates to not a number (NaN); otherwise, false.

範例

下列程式碼範例示範 IsNaN 方法。The following code example demonstrates the IsNaN method.

// This will return true.
if ( Single::IsNaN( 0 / zero ) )
{
   Console::WriteLine( "Single::IsNan() can determine whether a value is not-a-number." );
}
// This will return true.
if (Single.IsNaN(0 / zero))
{
    Console.WriteLine("Single.IsNan() can determine whether a value is not-a-number.");
}
' This will return true.
If Single.IsNaN(0 / zero) Then
    Console.WriteLine("Single.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.

注意

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

適用於

另請參閱