pow method

GfValue pow(
  1. BigInt exponent
)

Raises this element to a non-negative exponent.

Implementation

GfValue pow(BigInt exponent) {
  if (exponent.isNegative) {
    throw RohdHclException('Finite-field exponents must be non-negative.');
  }

  var result = field.one;
  var factor = this;
  var remainingExponent = exponent;
  while (remainingExponent != BigInt.zero) {
    if (remainingExponent.isOdd) {
      result *= factor;
    }
    remainingExponent >>= 1;
    if (remainingExponent != BigInt.zero) {
      factor = factor.square();
    }
  }
  return result;
}