NaN Constraint
NaNConstraint tests that a floating-point value is NaN (Not a Number).
Usage
Is.NaN
Is.Not.NaN
Examples
[Test]
public void NaNConstraint_Examples()
{
// NaN results from undefined operations
Assert.That(double.NaN, Is.NaN);
Assert.That(float.NaN, Is.NaN);
Assert.That(0.0 / 0.0, Is.NaN);
Assert.That(Math.Sqrt(-1), Is.NaN);
// Regular numbers are not NaN
Assert.That(42.0, Is.Not.NaN);
Assert.That(double.PositiveInfinity, Is.Not.NaN);
Assert.That(double.NegativeInfinity, Is.Not.NaN);
}
Notes
- NaN is the only value that is not equal to itself (
NaN != NaNis true). - Both
double.NaNandfloat.NaNare supported. - Infinity values are not NaN.
See Also
- EqualConstraint - For numeric comparisons with tolerance