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
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