I have written this code which precisely calculates the nth power of x by a recursive method.I compared my program with Java's pow(double, double) function, and most of the time I get comparable results, although sometimes pow is slow and the other times this program is slow.Can anyone suggest any improvements or the way Java implements this function?public double power(long x, int n) {    double pow = 1L;    if(n==0)        return 1;    if (n == 1)        return x;    if(n%2==0){        pow = power(x, n / 2);        return pow * pow;    }    else{        pow = power(x,n/2);        return pow * pow * x;    }}
Calculating nth power of x
java;algorithm;performance;mathematics