If you try to run the following code
public class Main {
public static void main(String[] args) {
long a = (long)Math.pow(13, 15);
System.ou
This is not a problem of precision. The Math.pow method performs an approximation of the result. To get the correct result use the following code.
long b = 13;
for(int i = 0; i != 14; i ++) {
b = b * 13;
}
System.out.println(b);
The output is the expected result 51185893014090757L.
More generally, the Math.pow method usage should be avoided when the exponent is an integer. First, the result is an approximation, and second it is more costly to compute.
The implementation of Math.pow (and most other methods in the Math class) is based on the network library netlib as the package "Freely Distributable Math Library" (see StrictMath javadoc). The implementation in C is available at e_pow.c.