ipfloat &ipfloat::operator +=(const ipfloat &ip){
int carry = 0, i, j, c;
ipfloat temp;
temp = *this;
int expoffset = abs(exp – ip.getExp());
int len = strlen(man);
if(exp<ip.getExp())
{
free(man);
man = (char*)malloc(sizeof(char)*(len+expoffset));
for(c=0; c<expoffset; c++)
man[c] = ‘0′;
exp+=c;
man[c] = ”;
man = strcat(man, temp.getMan());
i = strlen(ip.getMan()) – 1;
j = i;
}
else
{
i = strlen(man) – 1;
j = i-expoffset;
}
for(; i>=0 && j>=0; i–, j–)
{
man[i] = (char)((((int)(man[i] + ip.getMan()[j] – 2*’0′)) + carry)%10) + ‘0′;
carry = (temp.getMan()[i] + ip.getMan()[j] – 2*’0′ + carry >9)?1:0;
}
return *this;
}
Ahh! Code! This is what I’ve been working on the past couple of days. It’s my += operator overload for my arbitrary-precision floating point library. Why did it take so long? Well, I had a malloc problem elsewhere, and malloc problems pop up in weird places, not where the problem actually exists.
In any case, this works for almost everything…There’s still a problem with adding two numbers when the first number has more digits in the exponent, which is what I’m trying to fix. Hopefully I’ll finish the operations before Monday.
Update: Works for all addition! Hoorah!
What does this have to do with lsmsa? Well, it’s my distinction project, it should count for something.