Operator* Overloading question?
I think this may be more of a math problem then anything else; the problem is trying to use C++ code to do the math that I need. I'm trying to overload the * operator so I can multiply 2 objects of the same class. The class is called "HugeInt" and it's basically what it is, which allows me to go beyond the 4 billion limit of "double" in a 32-bit machine. But for the life of me I can't figure out how to multiply arrays. The addition part was easy, but multiplication just doesn't want to work for me. Anyway, here is the code
Code:
HugeInt HugeInt::operator *( const HugeInt &op2 ) const
{
HugeInt tempMultiply; // temporary result
int carryMultiply = 0;
for ( int i = 29; i >= 0; i-- )
{
tempMultiply.integer[ i ] =
integer[ i ] * op2.integer[ i ] + carryMultiply;
//determine whether to carry a 1
if ( tempMultiply.integer[ i ] > 9 )
{
tempMultiply.integer[ i ] %= 10; // reduce to 0-9
carryMultiply = 1;
} // end if
else // no carry
carryMultiply = 0;
} // end inner for
return tempMultiply;
}
If the code is absolutely sloppy, I apologize for that. Thanks for any help