Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- InfInt& InfInt::operator/(const InfInt& ob) const{
- StringCalculator calculator;
- if(*this < ob) {
- InfInt* zero = new InfInt("0");
- return *zero;
- }
- if(*this == ob) {
- InfInt* zero = new InfInt("1");
- return *zero;
- }
- string binaryA = this->BinaryStrFromInftInt();
- string binaryB = ob.BinaryStrFromInftInt();
- calculator.BinaryPaddingRemove(binaryB);
- calculator.BinaryPaddingRemove(binaryA);
- unsigned int lenA = binaryA.length();
- unsigned int lenB = binaryB.length();
- InfInt *temp = new InfInt(0);
- string tempBinaryResult;
- if (ob == *temp || *this == *temp) {
- delete(temp);
- throw "can't divide zero";
- }
- string R = "0"; //remain
- string Q = "";
- for (int i = 0; i < lenA; ++i) {
- Q += ZERO_ASCII;
- }
- for (int i = 0; i < lenA; ++i) {
- R += ZERO_ASCII;
- R[R.length() - 1] = binaryA[i];
- if(!calculator.BinaryBigger(binaryB, R)) {
- R = calculator.MinusBinaryStr(R, binaryB);
- Q[i] = ONE_ASCII;
- }
- }
- temp->SetInfIntFromBinaryStr(Q);
- bool isNeg = true;
- if((this->isNeg && ob.isNeg) || (!this->isNeg && !ob.isNeg)) {
- isNeg = false;
- }
- temp->isNeg = isNeg;
- temp->CutZeros();
- return *temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement