Skip to content

Generic degree-rendering formatters, millifahrenheit fix, drop *_real types (2.0.0)#5

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

Generic degree-rendering formatters, millifahrenheit fix, drop *_real types (2.0.0)#5
cleishm merged 2 commits into
mainfrom
feat/format-spec-rendering

Conversation

@cleishm

@cleishm cleishm commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Generic formatters: the 18 hand-written std::formatter specializations and 15 to_string overloads are replaced by two generic templates each. An empty format spec keeps the exact-count form (millicelsius(22500)"22500m°C"); any floating-point spec renders the value in scale degrees, so readable display no longer needs a lossy cast:

    std::format("{:.1f}", millicelsius(22534));  // "22.5°C"
    std::format("{:.1f}", delta_millifahrenheit(9000));  // "9.0Δ°F"

    Width/alignment pass through to the numeric part; specs on integer types were compile errors before, so this path is purely additive.

  • ⚠️ BREAKING — millifahrenheit ratio fix: millifahrenheit and delta_millifahrenheit used std::ratio<5, 900> (0.01 °F per count) instead of the documented std::ratio<5, 9000> (0.001 °F). Counts change meaning by 10×: temperature_cast<millifahrenheit>(fahrenheit(1)).count() was 100, is now 1000. The new conversion tests were written first and confirmed to fail against the old ratio.

  • ⚠️ BREAKING — *_real typedefs removed: celsius_real, kelvin_real, fahrenheit_real existed mainly as a display workaround; spec-based rendering covers that directly. Generic floating-point rep support in the templates remains (e.g. temperature<celsius_scale, delta<double>>). Migration: replace std::format("{:.1f}", temperature_cast<celsius_real>(x)) with std::format("{:.1f}", x).

  • Version bumped to 2.0.0 per semver (removed public API + count reinterpretation).

Test plan

  • New conversion tests demonstrably failed before the ratio fix, pass after
  • All nine empty-spec output strings pinned byte-for-byte (backward compat)
  • New spec-rendering test matrix across scales, precisions, deltas, width pass-through
  • Non-format build path verified: -DCONFIG_THERMO_STD_FORMAT=0 -fsyntax-only
  • 29/29 tests pass

cleishm added 2 commits July 10, 2026 15:06
…rop *_real types

Replace the 18 hand-written std::formatter specializations and 15
to_string overloads with two generic templates each. An empty format
spec keeps the exact-count form ("22500m°C"); any floating-point spec
renders the value in scale degrees, so display no longer needs a lossy
cast: std::format("{:.1f}", millicelsius(22534)) == "22.5°C".

BREAKING: millifahrenheit and delta_millifahrenheit used
std::ratio<5, 900> (0.01°F per count) instead of the documented
std::ratio<5, 9000> (0.001°F); counts change meaning by 10x.

BREAKING: the celsius_real/kelvin_real/fahrenheit_real typedefs are
removed - spec-based rendering covers their display use case directly.
Generic floating-point rep support in the templates remains.
@cleishm cleishm merged commit 4d29e65 into main Jul 10, 2026
6 checks passed
@cleishm cleishm deleted the feat/format-spec-rendering branch July 10, 2026 19:12
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