Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8177950

Math.rint says it returns argument on NaN, but does not always

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 8.1 Pro

      A DESCRIPTION OF THE PROBLEM :
      The following code prints false even though the Javadoc on Math.rint says it should prints true:

      public static void main(String[] args) throws Throwable {
          double nan = Double.NaN;
          System.out.println(Double.doubleToRawLongBits(-nan) == Double.doubleToRawLongBits(Math.rint(-nan)));
      }

      The Javadoc reads "If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument" which does not appear to be true. Please either change the Javadoc (e.g. what Math.abs does: "If the argument is NaN, the result is NaN") or change the internals of Math.rint to return the argument as stated.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the following:

      public static void main(String[] args) throws Throwable {
          double nan = Double.NaN;
          System.out.println(Double.doubleToRawLongBits(-nan) == Double.doubleToRawLongBits(Math.rint(-nan)));
      }


      REPRODUCIBILITY :
      This bug can be reproduced always.

            darcy Joe Darcy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: