Search Results for

    Show / Hide Table of Contents

    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

    1. NaN is the only value that is not equal to itself (NaN != NaN is true).
    2. Both double.NaN and float.NaN are supported.
    3. Infinity values are not NaN.

    See Also

    • EqualConstraint - For numeric comparisons with tolerance
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0