// Loop invariant: r * (b ^^ e) is the actual result
    for (;;)
    {
        if (e % 2 != 0)
        {
            r = mul(r, b, overflow);
            if (e == 1) return r;
        }
        b = mul(b, b, overflow);
        e /= 2;
    }
?

Reply via email to