double.NaN Equality in MS Test

Posted by RichK on Stack Overflow See other posts from Stack Overflow or by RichK
Published on 2010-03-26T15:35:03Z Indexed on 2010/03/26 15:53 UTC
Read the original article Hit count: 488

Filed under:
|
|

Why am I getting this result?

[TestMethod]
public void nan_test()
{
    Assert.AreEqual(1, double.NaN, 1E-1); <-- Passes
    Assert.AreEqual(1, double.NaN);       <-- Fails
}

What difference does the delta have in asserting NaN equals a number? Surely it should always return false. I am aware of IsNaN, but that's not useful here (see below).

Background: I have a function returning NaN (erroneously) , it was meant to be a real number but the test still passed. I'm using the delta because it's double precision equality, the original test used 1E-9.

© Stack Overflow or respective owner

Related posts about c#

Related posts about nan