Guys I'm working on class called LINT (large int) for learning purposes, and everything went ok till know. I'm stuck on implementing operator/(const LINT&). The problem here is that in when I want to divide LINT by LINT I'm getting into recursive fnc invocation i.e:
//unfinished
LINT_rep LINT_rep::divide_(const LINT_rep& bottom)const
{
typedef LINT_rep::Iterator iter;
iter topBeg = begin();
iter topEnd = end();
iter bottomBeg = bottom.begin();
iter bottomEnd = bottom.end();
LINT_rep topTmp;//for storing smallest number (dividend) which can be used to divide by divisor
while (topBeg != topEnd)
{
topTmp.insert_(*topBeg);//Number not large enough add another digit
if (topTmp >= bottom)
{//ok number >= we can divide
LINT_rep topShelf = topTmp / bottom;//HERE I'M RUNNING INTO TROUBLE
}
else
{
}
++topBeg;
}
return LINT_rep("-1");//DUMMY
}
What I'm trying to do is to implement this as if I would divide those numbers by hand, so for example having for a dividend 1589 and for divisor 27 I would go like so:
- check if first digit is >= divisor and if so divide
- if not add to the first digit another digit and check if a > b
At some point it will be bigger (in simplified scenario) and if so I have to divide but in this case I'm running into recursive call and I have no idea how to break it.
One note: as a tmp I have to use LINT instead of int for example because those numbers my not fit into int.
So generally what I'm asking for is there any other way to do division? Or maybe there is false logic in my thinking (quite possible).
Thank you.