title: What is the rationale for all comparisons returning false for IEEE754 NaN values?
body: <p>Why do comparisons of NaN values behave differently from all other values?
  That is, all comparisons with the operators ==, &lt;=, >=, &lt;, > where one or both values is NaN returns false, contrary to the behaviour of all other values.</p>
  
  <p>I suppose this simplifies numerical computations in some way, but I couldn't find an explicitly stated reason, not even in the <a href="http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF">Lecture Notes on the Status of IEEE 754</a> by Kahan which discusses other design decisions in detail.</p>
  
  <p>This deviant behavior is causing trouble when doing simple data processing. For example, when sorting a list of records w.r.t. some real-valued field in a C program I need to write extra code to handle NaN as the maximal element, otherwise the sort algorithm could become confused.</p>
  
  <p><strong>Edit:</strong>
  The answers so far all argue that it is meaningless to compare NaNs.</p>
  
  <p>I agree, but that doesn't mean that the correct answer is false,
  rather it would be a Not-a-Boolean (NaB), which fortunately doesn't exist.</p>
  
  <p>So the choice of returning true or false for comparisons is in my view arbitrary,
  and for general data processing it would be advantageous if it obeyed the usual laws
  (reflexivity of ==, trichotomy of &lt;, ==, >),
  lest data structures which rely on these laws become confused.</p>
  
  <p>So I'm asking for some concrete advantage of breaking these laws, not just philosophical reasoning.</p>
  
  <p><strong>Edit 2:</strong>
  I think I understand now why making NaN maximal would be a bad idea, it would mess up the computation of upper limits.</p>
  
  <p>NaN != NaN might be desirable to avoid detecting convergence in a loop such as</p>
  
  <pre><code>while (x != oldX) {
      oldX = x;
      x = better_approximation(x);
  }
  </code></pre>
  
  <p>which however should better be written by comparing the absolute difference with a small limit.
  So IMHO this is a relatively weak argument for breaking reflexivity at NaN.</p>