pow method
Computes the value of this number raised to an integral power. Follows semantics of Java Math.pow as closely as possible.
@param exp the integer exponent @return x raised to the integral power exp
Implementation
DD pow(int exp) {
if (exp == 0.0) return valueOf(1.0);
DD r = new DD.fromDD(this);
DD s = valueOf(1.0);
int n = exp.abs();
if (n > 1) {
/* Use binary exponentiation */
while (n > 0) {
if (n % 2 == 1) {
s.selfMultiplyDD(r);
}
n = n ~/ 2;
if (n > 0) r = r.sqr();
}
} else {
s = r;
}
/* Compute the reciprocal if n is negative. */
if (exp < 0) return s.reciprocal();
return s;
}