pow method

Big pow(
  1. int n
)

Return a Big whose value is the value of this Big raised to the power n. If n is negative, round to a maximum of Big.dp decimal places using rounding mode Big.rm.

Implementation

Big pow(int n) {
  if (n != ~~n || n < -maxPower || n > maxPower) {
    throw BigError(
      code: BigErrorCode.pow,
    );
  }
  var x = this, one = Big('1'), y = one, isNegative = n < 0;

  if (isNegative) n = -n;

  for (;;) {
    if ((n & 1) != 0) y = y.times(x);
    n >>= 1;
    if (n == 0) break;
    x = x.times(x);
  }

  return isNegative ? one.div(y) : y;
}