The first real arithmetic - schoolbook addition, limb by limb, propagating a carry in base 1000000000. The edge that matters is a carry that ripples off the top and grows the number by a limb.
Add two magnitudes limb by limb, carrying in base 1000000000, including a carry that adds a new top limb.
Adding in a large base is exactly the grade-school algorithm you already know, just
with nine-digit “digits”. Line the two magnitudes up from limb 0, add each pair
together with the incoming carry, and split the result: the low part (modulo the
base) is this limb, and anything above the base is the carry into the next limb.
Because a single limb plus a limb plus a carry can reach almost 2 * 10^9, a
64-bit accumulator holds the sum with room to spare.
The edge to pin is what happens when the carry runs off the end. `999999999999999999
turns every limb to zero in turn and leaves a final carry of1, which becomes a brand-new most-significant limb: the result is one limb longer than either input. Forget that trailing if carry > 0` and you silently drop the top of the number.func addMag(a, b mag) mag {if len(a) < len(b) { a, b = b, a }var out magvar carry uint64for i := range a {sum := uint64(a[i]) + carryif i < len(b) { sum += uint64(b[i]) }out = append(out, uint32(sum%Base))carry = sum / Base}if carry > 0 { out = append(out, uint32(carry)) }return out}