I'm working on overloading operators (still working on making a bignum decimal class) and I ran in to a snag. I can do all the normal arithmetic, but dividing seems to escape me. I came up with the idea that a/b = c where c is the number I want, and instead I said a = b*c and lets loops through all the possible combinations of c*b until it equals a. Although this works, it's so inefficient I can't divide numbers with 5 or more decimal places since it's on the order of O(10^n) (10 numbers for each decimal place, n = number of decimal places). I would like some ideas on how to do this, if more than one decimal place can be accomplished at a time that would be awesome, but if not it wouldn't be any worse than my other operators. Here is my code for the dividing operator as it is now.
Code:
//the function bdouble.check(bdouble) checks if the passed argument is the same
//value as the one that is calling the function
friend bdouble operator / (const bdouble a, const bdouble b)
{
bdouble<MAXSIZE> ret(0,0,0);
bdouble<MAXSIZE> mult_b = b;
//find 1/b to multiply by a
do{
++ret;
mult_b = b * ret;
}while(!mult_b.check(a));
return ret;
}