bigint bigint::pow (const bigint &that) const { bigint base = *this; if (that > 999) throw range_error ("exp too big"); int expt = that.smallint(); bigint result = 1; TRACE_POW; if (expt < 0) { base = 1 / base; expt = - expt; } while (expt > 0) { TRACE_POW; if (expt & 1) { //odd result = result * base; --expt; }else { //even base = base * base; expt /= 2; } } TRACE_POW; return result; }