I found the problem. It was a sly, sneaky out of bounds error. All it did was corrupt the heap behind the scenes, while still allowing the correct answer to be output if the numbers were small enough. Here is where it was:
Code:
int iSrc=(a.nSize*8)-1;
int iDest=(Terms[c]->nSize*8); //<!!!!!!!!!!! Should subtract there
while (iDest>(8*i)+j+(a.nSize*8)-1) {
if (static_cast<int>(iDest/8)>=ubound) std::cout << "<oob> " << std::flush;
SETBIT(Terms[c]->pNum[static_cast<int>(iDest/8)],iDest%8,0);
iDest--;
}
while (iSrc>=0) {
int BitSet=GETBIT(a.pNum[static_cast<int>(iSrc/8)],iSrc%8);
if (static_cast<int>(iDest/8)>=ubound) std::cout << "<oob> " << std::flush;
SETBIT(Terms[c]->pNum[static_cast<int>(iDest/8)],iDest%8,BitSet);
iSrc--;
iDest--;
}
while (iDest>=0) {
if (static_cast<int>(iDest/8)>=ubound) std::cout << "<oob> " << std::flush;
SETBIT(Terms[c]->pNum[static_cast<int>(iDest/8)],iDest%8,0);
iDest--;
}
The effect of that tiny error was that a single byte beyond the allocated memory was being zeroed hundreds of times. I guess that caused some heap damage or hurt its feelings or something.
I can now push it pretty high. I tried 3^5000, it took 5 seconds but it worked.
Any tips on how to speed it up?