Skip to content

Add format-spec rendering in display units (0.3.0)#2

Merged
cleishm merged 2 commits into
mainfrom
feat/format-spec-rendering
Jul 10, 2026
Merged

Add format-spec rendering in display units (0.3.0)#2
cleishm merged 2 commits into
mainfrom
feat/format-spec-rendering

Conversation

@cleishm

@cleishm cleishm commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

Mirrors thermo-cpp's new formatter-side rendering (cleishm/thermo-cpp#5): a non-empty format spec on a quantity renders the value in display units as a double, honoring the full floating-point spec syntax. The empty spec keeps today's exact-count form unchanged.

std::format("{:.1f}", millivolts(3300));      // "3.3V"
std::format("{}", millivolts(3300));          // "3300mV" (exact stored value, unchanged)
std::format("{:.1f}", milliampere_hours(200)); // "0.2Ah"
std::format("{:.1f}", 1050_cdB);              // "10.5dB"
std::format("{:.1f}", 1301_cdBm);             // "13.0dBm"
  • SI-prefixed precisions render in the base unit ("3.3V"); conventional non-decade precisions (mAh/Ah, Wh/kWh) render in their conventional unit via a new internal _display_unit trait ("0.2Ah", never "720.0C") — analogous to thermo's fahrenheit display family.
  • Decibel gains and levels render their value in dB with the reference symbol appended.
  • Non-empty specs were previously compile errors, so the change is purely additive; version bumped to 0.3.0 (also syncs the Doxyfile version, which was stale at 0.1.0).

Test plan

  • New spec-rendering test cases for quantities (V/A/Ω, Ah/Wh families, width pass-through) and for gains/levels
  • Existing empty-spec format tests pass unchanged
  • Non-format build path verified: -DCONFIG_ELECTRO_STD_FORMAT=0 -fsyntax-only
  • 23/23 tests pass

cleishm added 2 commits July 10, 2026 15:07
A non-empty format spec on a quantity now renders the value in display
units as a double, honoring the standard floating-point spec:
std::format("{:.1f}", millivolts(3300)) == "3.3V". SI-prefixed
precisions display in the base unit; conventional non-decade precisions
display in their conventional unit ("0.2Ah", never "720.0C"). Gains and
levels render in decibels: std::format("{:.1f}", 1050_cdB) == "10.5dB".

The empty spec keeps the exact-count form unchanged. Specs were
previously compile errors, so this is purely additive.
@cleishm cleishm merged commit 29bcf88 into main Jul 10, 2026
6 checks passed
@cleishm cleishm deleted the feat/format-spec-rendering branch July 10, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant