Do it using unsigned chars first, and limit the number to two limbs. Implement your algorithms that way. This way you can simply compare your results with the same operation done straightforward. You can make a unit test for that.
Addition and subtraction are trivial to implement.
For multiplication, use Karatsuba's or Toom-Cook's.
For division, there's nothing really cool that I know of.
>>Full code [Quartz3.c]
Loop in main Will Square result until it is larger than bMax( which is set to 1*10e4500) .... Largest number i have seen?!
//Mod'ed multiply a bit [should be a little faster again =) ]
...Not coming up with your own solutions....
*Shame on you /prog*
You'll never find a better solution to anything if you just use what's already on the table...
#include <stdio.h>
#include <stdlib.h>
const RRay = 1000; // Max array Size //
const CutOff = 1000000000; // Base
int aa[1020], ab[1020], ac[1020], aCount[1020], aZero[1020], aOne[1020], bCount[1020], bMax[1020];
int GOWFish(int a, int b){
int Ret=0;
if(a!=b){
if(a>b) Ret= 1;
if(a<b) Ret=-1;
}
return Ret;
}
//---------------------
int isLarger(int xa[], int xb[]){
int a, b, i, ret=0;
a = xa[RRay];
b = xb[RRay];
i =a+1;
ret = GOWFish(a, b);
while((ret==0) + (i>0)==2){
i--;
a = xa[i];
b = xb[i];
ret = GOWFish(a, b);
}
return ret;
}
//----------------------------------------------
void Add(int xa[], int xb[], int xc[]){
int i, iCarry=0, raymax=0;
raymax = xa[RRay];
if(xb[RRay]>raymax) raymax = xb[RRay];
xc[RRay] = raymax;
for(i=0;i<=xc[RRay];i++){
xc[i] = xa[i] + xb[i] + iCarry;
iCarry=0;
if(xc[i]>=CutOff){
iCarry++;
xc[i]-=CutOff;
}
if((i==xc[RRay])+(iCarry==1)+(xc[RRay]<RRay-1)==3) xc[RRay]++;
}
}
//----------------------------------
void CheckRRay(int xa[]){
int i, iTop=0;
for(i=0;i<RRay;i++){
if(xa[i]>0) iTop=i;
}
if(xa[RRay]!=iTop){ printf("Fixed RRay"); xa[RRay]=iTop;}
}