Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / mpow.cpp
blob328af89f67f872f90ca6bd72afcba106958c72d2
1 // Bignum power
3 #include "stdafx.h"
4 #include "defs.h"
6 unsigned int *
7 mpow(unsigned int *a, unsigned int n)
9 unsigned int *aa, *t;
11 a = mcopy(a);
13 aa = mint(1);
15 for (;;) {
17 if (n & 1) {
18 t = mmul(aa, a);
19 mfree(aa);
20 aa = t;
23 n >>= 1;
25 if (n == 0)
26 break;
28 t = mmul(a, a);
29 mfree(a);
30 a = t;
33 mfree(a);
35 return aa;