Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8246529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:32:07+00:00 2026-06-07T22:32:07+00:00

I came across this while debugging some unit tests that compared a returned single

  • 0

I came across this while debugging some unit tests that compared a returned single array against the expected results.

System.Single.NaN == System.Single.Nan;

The unit test was expecting true, but this evaluates to false. Why does this evaluate to false when the other static methods of single return true? Is NaN not a constant value ?

System.Single.MaxValue == System.Single.MaxValue;
System.Single.Epsilon == System.Single.Epsilon;
null == null;

http://msdn.microsoft.com/en-us/library/system.single.nan.aspx states: “Two NaN values are considered unequal to one another.” but this question is out of curiosity as to why this is so more than anything else.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:32:10+00:00Added an answer on June 7, 2026 at 10:32 pm

    Because the IEEE 754 standard (the one used for float and double) says so.

    To quote the wiki

    A comparison with a NaN always returns an unordered result even when comparing with itself. The comparison predicates are either signaling or non-signaling, the signaling versions signal an invalid exception for such comparisons. The equality and inequality predicates are non-signaling so x = x returning false can be used to test if x is a quiet NaN. The other standard comparison predicates are all signaling if they receive a NaN operand, the standard also provides non-signaling versions of these other predicates. The predicate isNaN(x) determines if a value is a NaN and never signals an exception, even if x is a signaling NaN.

    (note that .NET doesn’t support the signaling NaN, and probably treats it as non-signaling)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While debugging a crash, I came across this issue in some code: int func()
While debugging some code, I came across an array named default . I thought
While debugging javascript written by someone else, I came across some code that I've
While debugging into some Oracle code, I came across this query: SELECT TPM_TASK.TASKID FROM
While looking through some old code I came across this gem: MyObject o =
While looking at some conceptual questions in C,I came across this question in a
I came across this presentation while browsing SO some time ago, and it relates
While reading some documentation here , I came across this: unsigned unitFlags = NSYearCalendarUnit
While reading some Java source, I came across this line: ((Closeable) some_obj).close(); some_obj is
While debugging a WCF service I came across this issue. I use an HttpURLConnection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.