+ if (u.sign == v.sign) {
+ sign = positive;
+ } else {
+ sign = negative;
+ }
+
+ if (chunk_size == 1) {
+ E tmp;
+ tmp = static_cast< E >(u.chunk[0]) * static_cast< E >(v.chunk[0]);
+ num_type tnum = num_type(reinterpret_cast< N* >(&tmp), 2, sign);
+ return tnum;
+ }
+
+ std::pair< num_type, num_type > u12 = u.split();
+ std::pair< num_type, num_type > v12 = v.split();
+
+ /*
+ std::cout << "u:" << u12.first << " - " << u12.second << "\n";
+ std::cout << "v:" << v12.first << " - " << v12.second << "\n";
+ */
+
+ /* Aca esta la gracia de toda la cuestion:
+ * m = u1*v1
+ * d = u2*v2
+ * h = (u1+u2)*(v1+v2) = u1*u2+u1*v2+u2*v1+u2*v2
+ *
+ * h - d - m = u1*v2+u2*v1
+ * u1*v1 << base^N + u1*v2+u2*v1 << base^(N/2) + u2*v2
+ * m << base^N + (h - d - m) << base^(N/2) + d
+ */
+ num_type m = karatsuba(u12.first, v12.first);
+ num_type d = karatsuba(u12.second, v12.second);
+
+ num_type sumfst = u12.first + u12.second;
+ num_type sumsnd = v12.first + v12.second;
+ num_type h = karatsuba(sumfst, sumsnd);
+
+ /*
+ fflush(stdout); fflush(stderr);
+ std::cout << "m: " << m << "\n";
+ std::cout << "d: " << d << "\n";
+ std::cout << "h: " << h << "\n";
+ fflush(stdout); fflush(stderr);
+ */
+
+ num_type res, tmp;
+
+ /* tmp = h - d - m */
+ normalize_length(h, d);
+ tmp = h - d;
+ normalize_length(tmp, m);
+ /*
+ std::cout << "t: " << tmp << "\n";
+ std::cout << "m: " << m << "\n";
+ */
+ tmp = tmp - m;
+ //std::cout << "t: " << tmp << "\n";
+
+ /* Resultado final */
+ res = d << chunk_size;
+ res += tmp << (chunk_size / 2);
+ res += m;
+ res.sign = sign;
+
+ return res;
+}
+
+
+/* Potenciacion usando multiplicaciones sucesivas.
+ * Toma dos parametros u y v, devuelve u^v; asume v positivo.
+ */
+template < typename N, typename E >
+number < N, E > pot_ko(number< N, E > &u, number< N, E > &v)
+{
+ assert(v.sign == positive);
+ number< N, E > res, i;
+
+ res = u;
+ res.sign = u.sign;
+
+ for (i = 1; i < v; i += 1) {
+ res *= u;
+ }
+
+ return res;
+}
+
+/* Potenciacion usando división y conquista.
+ * Toma dos parametros u y v, devuelve u^v; asume v positivo.
+ *
+ * El pseudocódigo del algoritmo es:
+ * pot(x, y):
+ * if y == 1:
+ * return x
+ * res = pot(x, y/2)
+ * res = res * res
+ * if y es impar:
+ * res = res * x
+ * return res
+ *
+ * Es O(n) ya que la ecuación es T(n) = T(n/2) + O(1)
+ *
+ * El grafo que lo 'representa' (siendo los nodos el exponente y) algo como:
+ *
+ * 1 3
+ * _/ | \_
+ * _/ | \_
+ * / | \
+ * 6 1 6
+ * / \ / \
+ * / \ / \
+ * 3 3 3 3
+ * /|\ /|\ /|\ /|\
+ * 2 1 2 2 1 2 2 1 2 2 1 2
+ * / \ / \ / \ / \ / \ / \ / \ / \
+ * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
+ *
+ */
+template < typename N, typename E >
+number< N, E > pot_dyc(const number< N, E > &x, const number< N, E > &y)
+{
+ assert(y.sign == positive);
+ //std::cout << "pot(" << x << ", " << y << ")\n";
+ if (y == number< N, E >(1))
+ {
+ std::cout << "y es 1 => FIN pot(" << x << ", " << y << ")\n";
+ return x;
+ }
+ number< N, E > res = pot_dyc(x, y.dividido_dos());
+ //std::cout << "y.dividido_dos() = " << y.dividido_dos() << "\n";
+ //std::cout << "res = " << res << "\n";
+ res *= res;
+ //std::cout << "res = " << res << "\n";
+ if (y.es_impar())
+ {
+ //std::cout << y << " es IMPAR => ";
+ res *= x; // Multiplico por el x que falta
+ //std::cout << "res = " << res << "\n";
+ }
+ //std::cout << "FIN pot(" << x << ", " << y << ")\n\n";
+ return res;