Method IsNaN
IsNaN(double)
Determines whether the specified double-precision floating-point value is NaN (Not a Number). This method uses bit-level inspection for performance-critical scenarios.
public static bool IsNaN(double value)
Parameters
valuedoubleThe value to evaluate.
Returns
- bool
trueif the value is NaN; otherwise,false.
Examples
IsNaNFast(double.NaN) // returns true
IsNaNFast(0.0) // returns false
IsNaNFast(double.PositiveInfinity) // returns false
IsNaNFast(double.NegativeInfinity) // returns false
IsNaNFast(1.0 / 0.0) // returns false (infinity)
IsNaNFast(0.0 / 0.0) // returns true (NaN)
Remarks
IEEE 754: NaN values have all exponent bits set (0x7FF) and a non-zero mantissa. This avoids the overhead of IsNaN(double) and is suitable for tight loops.
IsNaN(float)
Determines whether the specified single-precision floating-point value is NaN (Not a Number). This method uses bit-level inspection.
public static bool IsNaN(float value)
Parameters
valuefloatThe value to evaluate.
Returns
- bool
trueif the value is NaN; otherwise,false.
Examples
IsNaN(float.NaN); // returns true
IsNaN(0f); // returns false
IsNaN(float.PositiveInfinity); // returns false
IsNaN(float.NegativeInfinity); // returns false
IsNaN(1f / 0f); // returns false (infinity)
IsNaN(0f / 0f); // returns true (NaN)