Bignum Bignum::operator*(const Bignum & bn) const { Bignum tmp; short symbol = 0, bit; const Bignum & self = *this; Bignum::Info info = Bignum::Info(self, bn); if (self[info.a_index] < 0) { symbol ^= 1; } if (bn[info.b_index] < 0) { symbol ^= 1; } self[info.a_index] = llabs(self[info.a_index]); bn[info.b_index] = llabs(bn[info.b_index]); for (int i = bignum_len - 1; i >= info.a_index; i--) { for (int j = bignum_len - 1; j >= info.b_index; j--) { bit = i - ( (bignum_len - 1) - j); tmp[bit] += (self[i] * bn[j]); tmp.carry(bit); } } if (symbol) { tmp[-tmp.bignum_used_len()] *= -1; } return tmp; }
///////////////////////////////////// // // Operator Computing // //////////////////////////////////// Bignum Bignum::operator+(const Bignum & bn) const { Bignum tmp; const Bignum & self = *this; Bignum::Info info = Bignum::Info(self, bn); if (bn[info.b_index] < 0) { tmp = bn; tmp[info.b_index] = llabs(tmp[info.b_index]); return self - bn; } else if (self[info.a_index] < 0) { tmp = self; tmp[info.a_index] = llabs(tmp[info.a_index]); return bn - tmp; } for (int i = bignum_len - 1; i >= 0; i--) { tmp[i] += self[i] + bn[i]; tmp.carry(i); } return tmp; }