← All papers
First page of When Double Rounding is Correct

When Double Rounding is Correct

Brett Saiki, Bill Zorn, Cynthia Richey, Zachary Tatlock

cs.PL Oct 6, 2026 · v2
Format-containment and double-rounding correctness theorems are mechanized in Lean 4, with proofs completed using LLM assistance; the mechanization is supplementary material.
Number libraries, which implement number formats and their arithmetic in software, are used to simulate hardware, making hardware behavior reproducible and thus verifiable and easier to design. However, modern machine learning accelerators are difficult to simulate, as they increasingly use specialized number formats that existing number libraries do not support. It is costly to extend these libraries using traditional methods: each combination of operation, format, and rounding mode typically requires a bespoke implementation. An easier way is to double round - compute at higher precision, then re-round - so that one high-precision kernel serves many formats, but double rounding is only known to be correct in select cases. We give a precise, efficiently checkable characterization of when double rounding is correct across many formats and rounding modes. Our result rests on a novel abstract number format that unifies fixed- and floating-point representations, reducing the correctness of double rounding to format containment: whether every value of one format is representable in another. We mechanized these results in Lean 4. In addition, we introduce a format inference algorithm that, given a sequence of operations, bounds each expression by a number format guaranteed to contain its result. We apply these insights in two ways. First, we present MPFX, a correctly-rounded, multi-precision number library that exploits correct double rounding to efficiently simulate many number formats. MPFX's correctly-rounded operations are up to 11x (mean: 6.05x) faster than MPFR's, and competitive with SoftFloat's - between 0.46x and 1.63x as fast (mean: 0.94x) - at the same precision. Second, in a case study, we implement a software simulation of a hardware specification using both SoftFloat and MPFX's primitives; the MPFX version is up to 13.5x faster.

Number libraries that simulate hardware number formats need a separate implementation for each combination of format, operation, and rounding mode. Double rounding (compute at higher precision, then re-round) avoids this, but it was known to be correct only in select cases.

An abstract number format A(p, exp, b) is introduced that unifies fixed- and floating-point formats. Correct double rounding then reduces to format containment, which has an efficient check on the format parameters. Containment and double-rounding rules for several rounding modes were mechanized in Lean 4: definitions were transcribed by hand, and LLMs were used to mechanize the prose proofs. A format inference algorithm bounds the format of each intermediate expression, and the results underpin MPFX, a C++ correctly-rounded multi-precision library.

Figure 4. Representable values on the real line for a floating-point format with an initial quantum q=2^{-2} and a maximum precision of p=2 .

MPFX's correctly-rounded operations are up to 11x faster than MPFR (mean 6.05x) and roughly on par with SoftFloat at the same precision (0.46x to 1.63x, mean 0.94x). In a case study simulating the MX dot-product specification, the MPFX version is up to 13.5x faster than the SoftFloat version.

Figure 10. Relative speedup over SoftFloat for each operation, datatype, and rounding mode. The top and bottom panels show single-precision (FP32) and half-precision (FP16), with the six operations along the x -axis. Within each operation, the bars are, left to right, MPFR, FloppyFloat (FP32 only), CPFloat, MPFX/HW, and MPFX/EFT, each as three bars for the RNE, RTP, and RTZ modes; the dashed line