Skip to content

Round debug float output to 4 decimal places#55879

Open
NickGerleman wants to merge 1 commit intofacebook:mainfrom
NickGerleman:export-D95041966
Open

Round debug float output to 4 decimal places#55879
NickGerleman wants to merge 1 commit intofacebook:mainfrom
NickGerleman:export-D95041966

Conversation

@NickGerleman
Copy link
Contributor

Summary:
Float values in debug layout metrics output (used by Fantom test assertions) are
subject to floating-point precision differences across platforms and compilers
(e.g., 66.6667 vs 66.66666412353516), causing flaky test comparisons.

This changes toString(const double&) in DebugStringConvertible.cpp to format
floats with 4 decimal places using snprintf("%.4f") and strip trailing zeros,
replacing double-conversion's ToShortest(). This is debug-only code (guarded
by #if RN_DEBUG_STRING_CONVERTIBLE) so the precision change is safe for all
consumers.

The double-conversion dependency is also removed from the BUCK file since it is
no longer used.

Output examples:

  • 0.0"0"
  • 100.0"100"
  • 66.66666412353516"66.6667"
  • 1.5"1.5"
  • 33.333333"33.3333"

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D95041966

Summary:
Float values in debug layout metrics output (used by Fantom test assertions) are
subject to floating-point precision differences across platforms and compilers
(e.g., `66.6667` vs `66.66666412353516`), causing flaky test comparisons.

This changes `toString(const double&)` in `DebugStringConvertible.cpp` to format
floats with 4 decimal places using `snprintf("%.4f")` and strip trailing zeros,
replacing `double-conversion`'s `ToShortest()`. This is debug-only code (guarded
by `#if RN_DEBUG_STRING_CONVERTIBLE`) so the precision change is safe for all
consumers.

The `double-conversion` dependency is also removed from the BUCK file since it is
no longer used.

Output examples:
- `0.0` → `"0"`
- `100.0` → `"100"`
- `66.66666412353516` → `"66.6667"`
- `1.5` → `"1.5"`
- `33.333333` → `"33.3333"`

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D95041966
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 3, 2026
@meta-codesync
Copy link

meta-codesync bot commented Mar 3, 2026

@NickGerleman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95041966.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants