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

Math.pow(x,y) function does not return an accurate value for pow(infinity,0)

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Happens with openJDK and also with Java8.

      A DESCRIPTION OF THE PROBLEM :
      (positive or negative) infinity to the power of 0 is indeterminate, per mathematical definition.
      However, Math.pow() is not handling this case correctly and returns 1.

      As per Java pow() function documentation, this is the "expected" behavior.
      https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/Math.html#pow(double,double)

      "Returns the value of the first argument raised to the power of the second argument. Special cases:
      If the second argument is positive or negative zero, then the result is 1.0."

      However, this is not right as seen in the literature:
      - https://en.wikipedia.org/wiki/Indeterminate_form
      - http://mathworld.wolfram.com/Indeterminate.html


      Looking at openJDK's 13 source code, it seems that this is *not* being handled as a special case in the files:
      - hotspot/cpu/x86/macroAssembler_x86_pow.cpp
      - java.base/share/native/libfdlibm/k_standard.c



      A bit unrelated references:
      ====================
      1. If we look at ECMA 262 definition for pow() (https://www.ecma-international.org/ecma-262/5.1/#sec-15.8.2.13), this special case is unfortunately not detailed.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac Main.java ; java Main

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Double.NaN

      ---------- BEGIN SOURCE ----------
      public class Main {

      public static void main(String[] args) {
      // any of the two cases should return Double.NaN (I guess) but currently returns 1
      System.out.println(Math.pow(Double.POSITIVE_INFINITY,0));
      System.out.println(Math.pow(Double.NEGATIVE_INFINITY,0));
      }

      }
      ---------- END SOURCE ----------

      FREQUENCY : always

            tongwan Andrew Wang
            pnarayanaswa Praveen Narayanaswamy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: