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

(math) wrong results on border conditions with NaN and Inf (solaris only)

XMLWordPrintable

    • 1.2beta4
    • sparc
    • solaris_2.5, solaris_2.5.1
    • Not verified

      From: Joe Ganley SJ2/1 (408)944-7232 <###@###.###>
      This does not look like form output to me.


      Greetings,

      I've noticed a bug (well, a discrepancy :-) in the java.lang.Math package
      included in the JDK 1.0 release for Solaris.

      Here is source code that exercises the four conditions listed in the API
      documentation for java.lang.Math that allegedly throw an ArithmeticException:

      ---

      import java.lang.*;

      public class foo extends java.applet.Applet {

        public void init() {
          try {
            System.out.println("log(-1.0) = " + Math.log(-1.0));
            System.out.println("sqrt(-1.0) = " + Math.sqrt(-1.0));
            System.out.println("pow(0.0,-1.0) = " + Math.pow(0.0, -1.0));
            System.out.println("pow(-1.0,0.5) = " + Math.pow(-1.0, 0.5));
          }
          catch (ArithmeticException exc) {
            System.out.println("An ArithmeticException was thrown.");
          }
        } // init()

      } // class foo extends java.applet.Applet

      ---

      This outputs:

      log(-1.0) = -Inf
      sqrt(-1.0) = NaN
      pow(0.0,-1.0) = -Inf
      pow(-1.0,0.5) = NaN

      with no ArithmeticException thrown. While this is perfectly reasonable
      behavior, it contradicts the docs, and I think throwing the exception is
      probably more useful behavior.

      Cheers,

      Joe
      ______________________________________________________________________________
       Joe Ganley, Ph.D. ###@###.###
       Senior Software Engineer (408)944-7232 / fax (408)894-2700
       Cadence Design Systems http://www.cs.virginia.edu/~jlg8k/
       

      Here are other examples from duplicate bug report 4038971:

      The following math functions are not behaving as specified in the java language specification.

      asin, and acos return 0 instead of NaN for arguments with absolute value greater than 1.
      log of negative numbers returns negative infinity instead of NaN
      pow called with NaN,0 returns Nan instead of 1.0
      pow called with 0, -1 returns -infinity instead of infinity
      pow called with -0, -4 returns -infinity instead of infinity

      Some examples:

      asin failed for c000000000000000 = -2 Expected 7ff8000000000000 Got: 0
      asin failed for c010000000000000 = -4 Expected 7ff8000000000000 Got: 0

      acos failed for c000000000000000 = -2 Expected 7ff8000000000000 Got: 0
      acos failed for c010000000000000 = -4 Expected 7ff8000000000000 Got: 0

      log failed for c09f400000000000 = -2000 Expected 7ff8000000000000 Got: fff0000000000000
      log failed for c09f37883126e979 = -1997.88 Expected 7ff8000000000000 Got: fff0000000000000

      pow failed for 7fffffffffffffff , 0 Expected 3ff0000000000000 Got: 7fffffffffffffff
      pow failed for 0 , bff0000000000000 Expected 7ff0000000000000 Got: fff0000000000000
      pow failed for 8000000000000000 , c010000000000000 Expected 7ff0000000000000 Got: fff0000000000000

      timothy.lindholm@Eng 1997-04-08

            hongzh Hong Zhang
            bhagen Benjamin Hagen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: