Scientific floating output turns zero into NaN text
perfloop-oss/cpp2rust · Uncatalogued correctness
https://perfloop.ai/t/oss/case_agccn45x2q
Verdict
VERIFIED · settled 2026-11-25 · merged as Cpp2Rust/cpp2rust#682
What happened: The check fails before this change and passes with it.
Hypothesis
Scientific output of an ordinary floating-point zero is incorrect. The valid call represented by `%e` and `0.0` produces `NaN.000000e-2147483648` instead of `0.000000e+00`. This can corrupt numeric output without a panic or write error. Consumer prevalence and performance effects are unmeasured.
The numeric branch of `format_c` converts this argument to `Arg::Double` and appends the text returned by `vsprintfp` (`libcc2rs/src/format.rs:62–85,122–127`). The input remains an exact `f64` zero at that boundary. The repository's existing floating tests demonstrate nonzero `%e` support, but do not cover this zero case. This is separate from integer narrowing and zero integer precision.
The new public-API checker `libcc2rs/tests/hunt_float_format.rs` planned a finite grid of every exponent field, both signs, four mantissas and 19 floating formats: 311,296 cases, not all possible doubles. It stopped after six cases. The reduced replay is a single `%e` conversion with IEEE-754 bits `0000000000000000`; no value search is needed to reproduce it. `cargo test --manifest-path libcc2rs/Cargo.toml --test hunt_float_format replay_first_float_mismatch -- --exact --nocapture` failed with exit 101 and printed `native="0.000000e+00" refcount=Ok("NaN.000000e-2147483648")`. Native output came from `libc::snprintf` with the same double argument. The rest of the planned grid remains untested by that run.
The Case should establish native-equivalent scientific zero output and check negative zero, precision, casing, signs and field width. Neighboring finite values, subnormals and non-finite arguments are useful controls for a broader normalization repair, not evidence that they all fail. The differential checker and its location are provisional proof methods rather than required product design.
The inspected live PR page https://github.com/Cpp2Rust/cpp2rust/pulls contains no scientific-formatting repair. The delegation at https://github.com/Cpp2Rust/cpp2rust/commit/7e86e6906c8b08b318df9f337a2e33fcffff64bf still reproduces this finite-zero case. Earlier NaN-literal translation work cannot correct a direct public-API call supplying exact zero. Available older file history is incomplete, and the inspected project documents identify no separate review archive.
Change to test: Make scientific formatting of finite zero native-compatible rather than producing NaN text or a sentinel exponent. Preserve sign, precision, casing and padding, and determine whether related floating normalization boundaries need the same correction.
Where it lives
perfloop-oss/cpp2rust · libcc2rs/src/format.rs
Evidence
The check fails before this change and passes with it: `In the C locale, format_c scientific e/E and compact g/G conversions of positive and negative f64 zero match snprintf for all combinations of #0- + flags, default precision and precisions 0..20/64/128/309/512/1024, and widths 0/1/4/5/6/7/8/10/12/20/80/350.`
Checks: 5 of 5 passed. Verification: no defect found.