\begin{helper}[Checked decimal rounding loop]
Let $d$ be a decimal sequence whose count is at most 768 and whose retained
cells are decimal digits.  Let $q$ be a usize with $q\leq18$.  Define
$D_j$ to be the value of cell $j$ when $j$ is below the count, and zero
otherwise, and put
\[
 F_k=\operatorname{foldl}(a,j\mapsto10a+D_j,0,[0,\ldots,k-1]).
\]
Then the extracted rounding range loop from zero through $q$ returns a U64
$n$ normally, and $n$ has value $F_q$.
\end{helper}
\begin{proof}
Unfold the range loop and its body in
\noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_round}.  Every $D_j$ is
strictly below 10: in the stored case this is the digit hypothesis, and in
the other case it is zero.  Induction on $k$ gives
\[
 F_{k+1}=10F_k+D_k\qquad\hbox{and}\qquad F_k<10^k.       \tag{1}
\]

Use the invariant that the current range start $k$ is at most $q$, the range
endpoint is still $q$, and the U64 accumulator has value $F_k$.  If the
iterator finishes, $k=q$ and the returned accumulator has the required
value.  Otherwise $k<q\leq18$.  Thus $k+1$ fits usize.  By (1), multiplying
the accumulator by ten yields a value below $10^{k+1}\leq10^{18}<2^{64}$,
so the checked U64 multiplication succeeds.  If $k$ is below the digit
count, then $k<768$ and the fixed array access is in bounds; its U8-to-U64
cast is exact, and adding the digit produces $F_{k+1}<2^{64}$, so the checked
addition succeeds.  If $k$ is not below the count, the body adds zero and
again produces $F_{k+1}$.  In both cases the next state satisfies the
invariant and the natural measure $q-k$ strictly decreases.

The preservation-and-finish reasoning is the loop rule
\noderef{ResultLoopPartial}; the displayed decreasing measure additionally
establishes normal termination.  Starting from $k=0$ and accumulator zero,
where the invariant holds definitionally, therefore yields a normal return
with value $F_q$.
\end{proof}
