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

conversion of double NaN to integral type doesn't produce zero

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      generic, solaris_2.4

      Description

      Java lang specification says (5.2.2 p.55):
      "If the floating-point number is NaN (#4.2.3), the result of the
      first step of the conversion is an int or long 0."

      But the program below prints anything but not 0:

      > cat conv023.java
      // Ident: @(#)conv023.java 1.1 96/02/09
      // Copyright 09 Feb 1996 Sun Microsystems, Inc. All Rights Reserved

      public class conv023 {
      public static void main(String args[]) {
      double zerod = 0.0d;
      double d;

      d = zerod / zerod;

      if (Double.isNaN(d)) {
      System.out.print("(byte) Double.NaN = ");
      System.out.println((byte) d);
      System.out.print("(short) Double.NaN = ");
      System.out.println((short) d);
      System.out.print("(int) Double.NaN = ");
      System.out.println((int) d);
      System.out.print("(long) Double.NaN = ");
      System.out.println((long) d);
      System.out.print('\\n');
      }
      }
      }
      > /usr/local/java/1.0/bin/javac conv023.java
      > /usr/local/java/1.0/bin/java conv023
      (byte) Double.NaN = -1
      (short) Double.NaN = -1
      (int) Double.NaN = 2147483647
      (long) Double.NaN = 9223372036854775807

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              apalanissunw Anand Palaniswamy (Inactive)
              Reporter:
              leosunw Leo Leo (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: