title: Java's Math.rint not behaving as expected when using NaN
body: <p>The javadoc for <code>Math.rint</code> says: "If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument." However, the following is false:</p>
  
  <pre class="lang-java prettyprint-override"><code>public static void main(String[] args) throws Throwable {
      double nan = Double.NaN;
      System.out.println(Double.doubleToRawLongBits(-nan) == Double.doubleToRawLongBits(Math.rint(-nan)));
  }
  </code></pre>
  
  <p>I am writing a compiler and I need the bits on NaN preserved. Is this a bug in the docs or in the runtime? Or does "same" not mean the same to me as it does in Java?</p>
  
  <p>I assume I have to <code>Double.isNaN</code> before the <code>rint</code> call and actually keep the same arguments to preserve my compiler's semantics.</p>
  
  <p>EDIT: This is not a duplicate of <a href="https://stackoverflow.com/questions/25050133/are-the-bit-patterns-of-nans-really-hardware-dependent">this</a> question. My question is about the javadoc and/or the JVM being wrong in its <code>rint</code> implementation, that one is about whether something is cross platform. Please do not mark the question as duplicate just because both deal w/ alternate forms of NaN on the JVM.</p>