Thank you all for your replies..
@laserlight .. I made mistake thank you for your help !!
Now i have the following code(WORKING) that does only converting and printing
Code:
#define RADIX 8 // Multiplication Complexity = O(a*b/RADIX^2)
#define BASE 100000000 // 10^RADIX
#define MAX_DIGITS 20005 // Precision
#define DT unsigned long long // Data type
struct bignum
{
int pos;
DT digits[MAX_DIGITS/RADIX+9];
bignum(DT num) // for initializations like bignum N=72039847
{
pos=0;
while(num)
{
digits[pos++]=num%BASE;
num/=BASE;
}
digits[pos]=digits[pos+1]=0; // extra padding
}
bignum(const char *str) // for initializations like bignum N="72039847"
{
pos=0;
int i,len=strlen(str),no=len/RADIX;
int start=len-RADIX,end=len;
DT temp;
while(no--)
{
temp=0;
for(i=start;i<end;i++) temp=10*temp+(str[i]-'0');
digits[pos++]=temp;
end=start;
start-=RADIX;
}
temp=0;
for(i=0;i<end;i++) temp=10*temp+(str[i]-'0');
if(temp) digits[pos++]=temp;
digits[pos]=digits[pos+1]=0; // extra padding
}
void print(bool new_line=0) // displays bignum if new_line required pass 1 as argument
{
int i=pos;
printf("%llu",digits[--i]);
while(i>0) printf("%08llu",digits[--i]);
if(new_line) printf("\n");
}
};
For the addition operation
Code:
bignum operator +(const bignum &A)
{
bignum result;
...
...
return result;
}
But the problem with this is i have to create a temp bignum to hold the result and then return it after the operation is done !.And if this exists in loop say
Code:
for(int i=0;i<1000000;i++)
bignum a=b+c;
The code becomes way too slow
I assume that if i write a function add in this way the code will be much faster !!
Code:
void add(const bignum &a,const bignum &b,bignum &c) // c=a+b;
{
}
Is there any way to speed up the earlier process since c=a+b looks much more intutive that add(a,b,c);
Thank you very much !