由买买提看人间百态

topics

全部话题 - 话题: tempdigit
(共0页)
i**********e
发帖数: 1145
1
4. 很久以前写的大数 class. 基本思路很简单,就是小学的乘法 + carry.
BigInt BigInt::multiply(const BigInt &b) const
{
BigInt answer;
BigInt temp;

int carry = 0;
for (int i = 0; i < b.numDigits; i++)
{
temp.numDigits = this->numDigits + 1;
int down = b.digits[i];
for (int j = 0; j <= this->numDigits; j++)
{
int up = (j < this->numDigits) ? this->digits[j] : 0;
int tempDigit = up * down + carry;
temp.digits[j] = tempDigit % 10;
carry = tempDigit / 10;
}
temp.s... 阅读全帖
(共0页)