2 *****************************************************************************
4 Implementation of interfaces for (square-and-multiply) exponentiation.
6 See exponentiation.hpp .
8 *****************************************************************************
9 * @author This file is part of libff, developed by SCIPR Lab
10 * and contributors (see AUTHORS).
11 * @copyright MIT license (see LICENSE file)
12 *****************************************************************************/
14 #ifndef EXPONENTIATION_TCC_
15 #define EXPONENTIATION_TCC_
17 #include <libff/common/utils.hpp>
22 template<typename FieldT, mp_size_t m>
23 FieldT power(const FieldT &base, const bigint<m> &exponent)
25 FieldT result = FieldT::one();
27 bool found_one = false;
29 for (long i = exponent.max_bits() - 1; i >= 0; --i) {
31 result = result * result;
34 if (exponent.test_bit(i)) {
36 result = result * base;
43 template<typename FieldT>
44 FieldT power(const FieldT &base, const unsigned long exponent)
46 return power<FieldT>(base, bigint<1>(exponent));
51 #endif // EXPONENTIATION_TCC_