\begin{lemma}
For every real $x$, natural number $G$, signed 32-bit scalars $p,p_f$,
unsigned 64-bit scalars $S,S_f,O$, biased pair $fp$, and binary64 carrier
$t$, use $\operatorname{val}$ for scalar values and put
\[
\begin{gathered}
 U=2^{52},\quad T=2047U,\quad H=2^{1024}-2^{970},\quad
 P=\operatorname{val}(p),\quad F=\operatorname{val}(p_f),\\
 a=\lfloor G/2\rfloor,\quad \delta=2^{P-1076},\quad
 u=2^{P-1075},\quad L=P_{\mathbb N}U+(a-U),\\
 \tau\ \Longleftrightarrow\ (x=G\delta\ \land\ G\bmod4=1),\qquad
 c\ \Longleftrightarrow\ (G\bmod2=1\ \land\ \neg\tau).
\end{gathered}
\]
Here $P_{\mathbb N}=\max(P,0)$ viewed as a natural number, and subtraction
in $L$ is natural-number subtraction. Assume all of the following:
\[
\begin{gathered}
 x>0,\qquad P>0,\qquad 2^{53}\le G<2^{54},\qquad
 \operatorname{val}(O)=U,\\
 \bigl(\operatorname{val}(S)=2^{53}\ \land\
       S_f=O\ \land\ F=P+1\bigr)
 \ \lor\
 \bigl(\operatorname{val}(S)<2^{53}\ \land\
       S_f=S\ \land\ p_f=p\bigr),\\
 \operatorname{val}(S)=
   \begin{cases}a+1&c,\\a&\neg c,\end{cases}
 \qquad G\delta\le x<(G+1)\delta,\qquad au\le x\le(a+1)u,\\
 \neg c\ \Longrightarrow\ |x-au|\le|x-(a+1)u|,\qquad
 c\ \Longrightarrow\ |x-(a+1)u|\le|x-au|,\\
 \neg c\ \Longrightarrow\
   \bigl(|x-au|=|x-(a+1)u|\ \Longrightarrow\ L\bmod2=0\bigr),\\
 c\ \Longrightarrow\
   \bigl(|x-(a+1)u|=|x-au|\ \Longrightarrow\ (L+1)\bmod2=0\bigr).
\end{gathered}
\]
Assume also that $t$ is the unrestricted assembly of $fp$, in the sense of
\noderef{DecimalGoalVocabularyDefault}, and that the final pair is
\[
 fp=
 \begin{cases}
   (0,2047),&F\ge2047,\\
   (S_f\mathbin{\mathtt{\&}}\mathbin{\mathtt{\sim}}O,\ p_f),&F<2047.
 \end{cases}
\]
The complement and conjunction here are the extracted 64-bit scalar
operations, and the displayed pairs list mantissa followed by biased
exponent. Then
$\texttt{roundsMagnitude}(x,t)$ holds, with exactly the meaning of
\noderef{DecimalGoalVocabularyDefault}.
\end{lemma}
\begin{proof}
The bounds on $G$ give $U\le a<2U$, and the selection formula gives
$U\le\operatorname{val}(S)\le2U$. In either carry case $F>0$.
Write $V(n)$ for the finite-magnitude decoder in
\noderef{Binary64FiniteMagnitudeStrictMono}. That lemma says that $V$ is
strictly increasing below $T$.

First record two bit-field calculations used in finite assembly.
For $U\le z<2U$, clearing bit $52$ gives $z-U$: the remainder of the
64-bit clearing mask modulo $2^{53}$ is $U-1$, so its conjunction with
$z$ is $z\bmod U=z-U$. This applies to $S_f$ whenever $F<2047$,
since the carry case has $S_f=O$ and the noncarry case has $S_f=S<2U$.
Also, if $b<U$, then $b$ and $eU$ have disjoint set bits, so
$b\mathbin{\mathtt{OR}}eU=b+eU$. For $1\le F\le2046$ the exponent
shift is smaller than $2^{64}$ and the cast remainder is $F$ itself.
Consequently unrestricted assembly has value
\[
 \operatorname{val}(t)=F_{\mathbb N}U+
                         (\operatorname{val}(S_f)-U).
 \tag{1}
\]
In the noncarry case, substituting the selection formula into (1) gives
$L+1$ if $c$, and $L$ otherwise. In the carry case,
$\operatorname{val}(S)=2U$ forces $c$ and $a=2U-1$; hence (1) is
$(P_{\mathbb N}+1)U=L+1$. Thus, in all finite cases,
\[
 \operatorname{val}(t)=
   \begin{cases}L+1&c,\\L&\neg c,\end{cases}
 \quad P_{\mathbb N}\le2046,\quad L+1\le T.
 \tag{2}
\]

Now suppose $F\ge2047$. The final pair and unrestricted assembly give
$\operatorname{val}(t)=T$. If there was a carry, then $P\ge2046$,
$c$ holds, and $a=2U-1$. Since $G$ is odd under $c$,
$G=4U-1=2^{54}-1$. Thus $\delta\ge2^{970}$ and
\[
 H=(2^{54}-1)2^{970}\le G\delta\le x.
\]
Without a carry, $P=F\ge2047$, so $\delta\ge2^{971}$ and
$G\ge2^{53}$ imply $x\ge2^{1024}\ge H$.
Together with $x>0$ these are precisely the infinity requirements of
$\texttt{roundsMagnitude}$.

For the rest assume $F<2047$, so (1)--(2) hold and the assembled word is
strictly below $T$. If $L+1=T$, the bounds on $a$ force
$P_{\mathbb N}=2046$ and $a=2U-1$. Finiteness and (2) force $\neg c$.
If $G$ were odd, $\neg c$ would force $\tau$; but then
$G=2a+1=2^{54}-1$ has remainder $3$ modulo $4$, contradicting $\tau$.
Hence $G=2a$ is even. Here $\delta=2^{970}$, and the strict cell
upper bound gives
\[
 x<(G+1)\delta=H.
\]
Direct decoding gives $V(L)=a2^{971}=au\le x$.
Every distinct finite carrier has a smaller word than $L=T-1$ and hence,
by strict monotonicity, a value strictly below $V(L)$. Its distance to $x$
is strictly larger than the distance of $V(L)$ to $x$. This proves every
finite comparison, and there is no distance equality requiring parity.

It remains that $L+1<T$. The two words decode to
\[
 V(L)=au,\qquad V(L+1)=(a+1)u.                 \tag{3}
\]
For $P_{\mathbb N}\le2045$ this is
\noderef{Binary64AdjacentNormalValues}. For $P_{\mathbb N}=2046$,
$L+1<T$ implies $a+1<2U$; division and remainder by $U$ give
the exponent $2046$ and fractions $a-U$ and $a+1-U$ directly,
which proves (3) at spacing $u=2^{971}$.

In this interior case $x<H$. Indeed, if $P_{\mathbb N}\le2045$,
then $u\le2^{970}$ and
$x\le(a+1)u\le2^{53}2^{970}=2^{1023}<H$.
If $P_{\mathbb N}=2046$, then $a+1\le2^{53}-1$ and
\[
 x\le(a+1)2^{971}
   \le(2^{53}-1)2^{971}
   =2^{1024}-2^{971}<H.
\]

Finally, (3) and the hypotheses place $x$ between the two adjacent
decoded values. Formula (2) and the assumed local distance inequalities
select a nearest endpoint, with even raw word in the equality case.
For completeness, an arbitrary finite competing word below $L$ has
decoded value strictly below $V(L)$, and a competing word above $L+1$
has decoded value strictly above $V(L+1)$, by strict monotonicity.
A word on the opposite side from the selected endpoint is at least as
far from $x$ as the opposite endpoint, so the assumed local comparison
gives the required global comparison. A word beyond the selected
endpoint on its own side is strictly farther, since $x$ lies in the cell.
If a global comparison is an equality, the comparison with the opposite
endpoint must therefore also be an equality; the corresponding assumed
parity implication makes the selected word even.
Thus all quantified finite comparisons and their equality clauses hold.
Together with $0<x$, $\operatorname{val}(t)<T$, and $x<H$, these are exactly
the remaining clauses of $\texttt{roundsMagnitude}(x,t)$.
\end{proof}

