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

Math.pow() produces incorrect value

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      A DESCRIPTION OF THE PROBLEM :
      Math.pow() method produces incorrect value when the correct value is within the range of a "long" variable.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Please refer to the source code below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Please refer to the source code below.
      ACTUAL -
      Please refer to the source code below.

      ---------- BEGIN SOURCE ----------
      public class BugReport {
      // The method Math.pow calculates an incorrect value
      // when the correct value is within the permitted range for a long variable.

      public static void main(String[] args) {

      final long correct = 61L * 61L * 61L * 61L * 61L * 61L * 61L * 61L * 61L * 61L;
      System.out.println("The correct value of 61^10 is " + correct);

      final long incorrect = (long) Math.pow(61, 10);
      System.out.println("The incorrect value of 61^10 is " + incorrect + " as produced by Math.pow()");
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: