evaluateAt method

int evaluateAt(
  1. int a
)

@return evaluation of this polynomial at a given point

Implementation

int evaluateAt(int a) {
  if (a == 0) {
    // Just return the x^0 coefficient
    return getCoefficient(0);
  }
  if (a == 1) {
    // Just the sum of the coefficients
    int result = 0;
    for (int coefficient in _coefficients) {
      result = _field.add(result, coefficient);
    }
    return result;
  }
  int result = _coefficients[0];
  final size = _coefficients.length;
  for (int i = 1; i < size; i++) {
    result = _field.add(_field.multiply(a, result), _coefficients[i]);
  }
  return result;
}