+ /// Increments the number by 1.
+ pub fn inc1(&mut self) {
+ let mut idx = 0;
+ // This loop adds "(1 << idx)". If there is no more carry, we leave.
+ while idx < self.data.len() {
+ let cur = self.data[idx];
+ let sum = u64::wrapping_add(cur, 1);
+ self.data[idx] = sum;
+ if sum >= cur {
+ // No overflow, we are done.
+ return;
+ } else {
+ // We need to go on.
+ idx += 1;
+ }
+ }
+ // If we came here, there is a last carry to add
+ self.data.push(1);
+ }
+