Skip to content

fix(fl::ftoa): pad trailing zeros at precision=2; fix substr heap-promote test data - #2971

Merged
zackees merged 2 commits into
masterfrom
fix/ftoa-precision-pad-and-substr-test
Jun 8, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/ftoa-precision-pad-and-substr-test

Conversation

@zackees

@zackees zackees commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Closes #2970

Summary

Two pre-existing failures in bash test fl_stl_string --cpp on master that have been blocking the unit tests linux CI gate on every PR branched from master after #2961/#2962.

Fix 1 — fl::ftoa / printf_detail::format_float drops trailing zeros

tests/fl/stl/string.cpp:5018 ("fl::string - append float and double") expected "0.00"/"1.00" from s.append(0.0f)/s.append(1.0f) (the append path calls fl::ftoa(val, buf, 2)), but the underlying fl::printf_detail::format_float(value, precision) in src/fl/stl/stdio.h was returning "0.0"/"1.0".

Root cause:

  • The pad-zero loop terminated at temp_multiplier > 1, dropping the last zero digit.
  • The digit-emission was guarded by if (frac_part > 0), so all fractional digits were suppressed when the value was integer-valued.

Replaced the post-fact pad-and-emit logic with a clean positional emitter that always writes exactly precision fractional digits. Verified against 0.0f/1.0f/-1.5f (test cases), 3.14159f@3 (precision-override subcase), and -0.05f (sign preservation when integer part rounds to zero).

Fix 2 — substr test data was exactly 64 chars

tests/fl/stl/string.cpp:6225 ("substr/substring on heap-promoted string (>64 chars)") used a 64-char literal — exactly FASTLED_STR_INLINED_SIZE — so the string stayed inline and FL_CHECK_GT(s.size(), 64) failed. Extended the literal to 66 chars (..._XYZW) so it actually heap-promotes; the substr(2, 4) == "CDEF" subcase is unaffected since only the suffix changed.

Why this unblocks CI

The unit tests linux job has been failing on every PR for these two pre-existing test failures unrelated to the PR's own changes. Landing this fixes the gate for everyone.

Test plan

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Floating-point formatting now always shows the exact number of decimal places requested (including trailing zeros) and preserves the negative sign for values that round to zero.
  • Tests

    • Increased test string length to improve substring coverage.
    • Updated test baseline data to reflect a measured size change.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 60255871-22f2-492c-ab74-bf294d2d59c9

📥 Commits

Reviewing files that changed from the base of the PR and between 793c73d and 55cc80f.

📒 Files selected for processing (3)
  • src/fl/stl/stdio.h
  • tests/data/esp32s3_bloat_baseline.txt
  • tests/fl/stl/string.cpp

📝 Walkthrough

Walkthrough

Fixes float formatting to always produce the requested fractional digits and correctly sign negative values that round to zero; extends a substring test input to force heap promotion; and updates the esp32s3 bloat baseline value.

Changes

Float formatting precision and test data corrections

Layer / File(s) Summary
Float formatting precision and sign handling
src/fl/stl/stdio.h
format_float now emits a leading - for negative values that round to integer 0 and always writes exactly precision fractional digits by iterating digit-by-digit over the rounded fractional part.
Heap-promoted substring test data correction
tests/fl/stl/string.cpp
long_prefix literal is lengthened so the test input exceeds the inline string capacity threshold and properly exercises heap-promoted substring behavior.
ESP32-S3 bloat baseline update
tests/data/esp32s3_bloat_baseline.txt
Baseline numeric value updated from 338372 to 338493.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nibble code and count each dot and zero,
I tuck a minus sign where rounding made it hero.
A long string hops to heap to prove its case,
Baselines nudged up in their rightful place.
Hooray — tests march on with steadier pace!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: fixing fl::ftoa to pad trailing zeros at precision=2 and fixing the substr heap-promote test data.
Linked Issues check ✅ Passed The PR fully addresses both requirements from issue #2970: format_float now honors precision and pads trailing zeros, and the substr test data literal was extended to exceed the 64-char inline limit.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #2970: the format_float rewrite, the substr test literal extension, and the baseline update to account for the intentional size increase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ftoa-precision-pad-and-substr-test

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
tests/fl/stl/string.cpp

tests/fl/stl/string.cpp:5:10: fatal error: 'fl/stl/compiler_control.h' file not found
5 | #include "fl/stl/compiler_control.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/55cc80f17da5ed3c0f6ce5a0412e9389dc85f029-96a30a792f3a00aa/tmp/clang_command_.tmp.ff49a4.txt
++Contents of '/tmp/coderabbit-infer/55cc80f17da5ed3c0f6ce5a0412e9389dc85f029-96a30a792f3a00aa/tmp/clang_command_.tmp.ff49a4.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple"
"x86_64-unknown-linux-gnu" "-emit-

... [truncated 1093 characters] ...

ang/install/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-fdeprecated-macro" "-ferror-limit" "19" "-fgnuc-version=4.2.1"
"-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/96a30a792f3a00aa/file.o" "-x" "c++"
"tests/fl/stl/string.cpp" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

zackees and others added 2 commits June 7, 2026 19:06
Two pre-existing failures in `bash test fl_stl_string --cpp` on master:

1. `fl::printf_detail::format_float` (the underlying impl behind
   `fl::ftoa` and printf's `%f`) was emitting "0.0"/"1.0" for
   `precision=2` calls on integer-valued floats. The legacy
   pad-zero loop terminated at `temp_multiplier > 1`, dropping the
   final zero, and the digit-emission branch was guarded by
   `frac_part > 0`, suppressing all fractional output when zero.
   Replaced with a clean exact-`precision`-digit emitter that
   computes each digit positionally so "0.0f" -> "0.00",
   "1.0f" -> "1.00", "-1.5f" -> "-1.50", and small negatives like
   "-0.05f" preserve their sign even when the integer part rounds
   to zero.

2. Test "substr/substring on heap-promoted string (>64 chars)"
   used a 64-char literal — exactly `FASTLED_STR_INLINED_SIZE` —
   so the string stayed inline and `FL_CHECK_GT(s.size(), 64)`
   fired. Extended the literal to 66 chars to actually heap-
   promote.

Together these unblock the `unit tests linux` CI gate that was
failing on every PR branched from master after #2961/#2962.

Closes #2970

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…a rewrite)

format_float in src/fl/stl/stdio.h grew by ~121 B after the rewrite to
honor the precision/pad argument. Update the baseline so the bloat-
regression gate passes. Net regression is small and one-time (the gate
exists to catch ongoing drift, not intentional fixes).
@zackees
zackees force-pushed the fix/ftoa-precision-pad-and-substr-test branch from 793c73d to 55cc80f Compare June 8, 2026 02:06
@zackees
zackees merged commit 88e03dc into master Jun 8, 2026
6 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 8, 2026
@zackees
zackees deleted the fix/ftoa-precision-pad-and-substr-test branch August 21, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fl_stl_string: 2 pre-existing failures on master (ftoa precision + substr test-data bug)

1 participant