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.

返回

如果 f 计算为非数字 (NaN),则为 true;否则为 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.

备注

如果 SinglePositiveInfinityNegativeInfinity,则 IsNaN 返回 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.

适用于

另请参阅