I'm writing a large numbers class just for fun and currently use no pointers. I basically have objects with functions for performing operations and these functions return the answer as another LargeNumber. Sowill return another (LargeNumber)c that equals a + b. What I want to do is define it to take and return pointers because this would be (supposedly) faster. I was working with it earlier and got a couple errors about scope and pointers so I figure I was doing it wrong.Code:(LargeNumber)c = (LargeNumber)a.add((LargeNumber)b);
Here's my multiply function, it's short because it uses add() and other routines, I added a couple comments.I want to turn this into a function that takes a pointer of a LargeNumber and returns a pointer to another LargeNumber.Code:LargeNumber LargeNumber::mul(LargeNumber x) { LargeNumber muls[2] = LargeNumber(0,0,0); muls[0] = simplemul(x.getDigit(x.getLength()));//simplemul multiples the entire number by a single digit muls[0].setSign(1);//sign figured out latter, all positive for addition bool yy = 1; for(int i = x.getLength() - 1; i > 0; i--)//elementary arithmetic, multiply top by each digit in the bottom... { muls[yy] = simplemul(x.getDigit(i)); muls[yy].setSign(1); muls[yy].mul10(x.getLength() - i); //adds a zero to the right muls[yy] = muls[yy].add(muls[!yy]); yy = !yy; } muls[!yy].setDec(getDec() + x.getDec());//finds the decimal if(getSign() == 0 && x.getSign() == 0) muls[!yy].setSign(1); else muls[!yy].setSign(getSign() && x.getSign()); return muls[!yy]; }
Just for simplicity I don't need you to rewrite the entire function. Just pointify this and/or explain somethingCode:LargeNumber* LargeNumber::mul(LargeNumber* x) { LargeNumber muls[2] = LargeNumber(0,0,0); //Define muls[2] somehow... muls[0] = simplemul(x.getDigit(x.getLength())); //do stuff (I understand x->function()??) return muls[yy]; }Code:LargeNumber* a = &LargeNumber(...); LargeNumber* b = &LargeNumber(...) LargeNumber* c = a->mul(b); //Alternatively I assume this would work?? LargeNumber a = LargeNumber(...); LargeNumber b = LargeNumber(...); LargeNumber* c = a.mul(&b);



LinkBack URL
About LinkBacks



