Beispiel #1
0
  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;
  }
Beispiel #2
0
  Bignum::Bignum(const Bignum & bn) {
    init();
    decimal_point = bn.decimal_point;
    bignum_len = bn.bignum_len;

    for (int i = bignum_len - bn.bignum_used_len(); i < bignum_len; i++) {
      bignum[i] = bn[i];
    }
  }