* @return evaluation of this polynomial at a given point */
| 96 | * @return evaluation of this polynomial at a given point |
| 97 | */ |
| 98 | int ModulusPoly::evaluateAt(int a) { |
| 99 | int i; |
| 100 | if (a == 0) { |
| 101 | // Just return the x^0 coefficient |
| 102 | return getCoefficient(0); |
| 103 | } |
| 104 | int size = coefficients_->size(); |
| 105 | if (a == 1) { |
| 106 | // Just the sum of the coefficients |
| 107 | int result = 0; |
| 108 | for (i = 0; i < size; i++) { |
| 109 | result = field_.add(result, coefficients_[i]); |
| 110 | } |
| 111 | return result; |
| 112 | } |
| 113 | int result = coefficients_[0]; |
| 114 | for (i = 1; i < size; i++) { |
| 115 | result = field_.add(field_.multiply(a, result), coefficients_[i]); |
| 116 | } |
| 117 | return result; |
| 118 | } |
| 119 | |
| 120 | Ref<ModulusPoly> ModulusPoly::add(Ref<ModulusPoly> other) { |
| 121 | if (&field_ != &other->field_) { |
no test coverage detected