Repository navigation
Fix scientific and compact formatting of zero - #682
Merged
nunoplopes merged 4 commits intoNov 25, 2026
Merged
Conversation
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Contributor
|
@perfloop-agent don't add cargo tests. We want only C tests so we can ensure we give the same result as C/C++. |
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Contributor
Author
|
The added Rust tests have been replaced with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
format_cturns%ewith0.0intoNaN.000000e-2147483648instead of0.000000e+00. For the same zero argument,%gand%Gpanic in debug builds and emitNaN.in release builds. The refcountprintf,fprintfandsnprintfpaths now format scientific (%e/%E) and compact (%g/%G) zeros directly, avoiding logarithmic normalization.The shared helper preserves negative zero and applies precision, signs and field width. Scientific zero uses
e+00orE+00. Compact zero uses fixed form: without#, it emits0regardless of precision;%#.4gemits0.000, while%#.0gkeeps the decimal point as0.. A+sign takes precedence over a space sign, and left alignment overrides zero padding.The C fixture in
tests/unit/printf_zero.ccompares both translation models with native output. It covers these cases, including unpadded and zero-padded space signs, widths shorter than the value, and multiple conversions in one format.Nonzero, subnormal and non-finite values, and
%f/%F, retain the existing formatter; this is not a general normalization or rounding repair.Testing: Lit's zero-formatting, snprintf and printf fixtures passed: 3 passed, 0 failed, 0 skipped. Cargo's existing formatting tests passed: 6 passed, 0 failed, 0 ignored. Rustfmt, clang-format and Clippy checks passed.
Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.