Skip to content

Use C++ decimal punctuation for floating-point output - #106

Open
trestoncuzzort wants to merge 2 commits into
boostorg:developfrom
trestoncuzzort:feature/custom-locale-round-trip
Open

trestoncuzzort wants to merge 2 commits into
boostorg:developfrom
trestoncuzzort:feature/custom-locale-round-trip

Conversation

@trestoncuzzort

@trestoncuzzort trestoncuzzort commented Oct 26, 2026 •

Copy link
Copy Markdown

An unnamed C++ numpunct locale can make lexical_cast<std::string>(1.25) produce "1.25" while lexical_cast<double> expects "1#25". The same mismatch affects wide output.

Use Boost.Charconv for float/double output and translate the decimal point through the matching C++ facet. Extended long double keeps its existing formatter, with the C decimal point normalized first: Charconv's general-precision path still has the problems discussed in boostorg/charconv#158. This preserves the existing precision, signed-zero and inf/NaN behavior while fixing the locale mismatch for all three types.

This adds a compiled Charconv dependency. B2, CMake, module builds and the standalone no-exceptions test are linked accordingly; manual linking is documented. The module test's existing sample path is also corrected, and the new locale regression runs through both headers and the module.

Fixes #98. The new Charconv link requirement is documented above for review.

Validation:

  • Full GCC 16 C++11 and Clang 23 C++17 targets pass: 32 checks, including 29 runtime tests, each. Pristine targets pass 31 checks/28 runtime tests; the new outside locale probe fails 18 expectations before the change.

  • CMake header tests pass 28/28; the corrected standalone C++20 module tests pass 6/6 with Clang and import std disabled. The unchanged module's five programs pass in a baseline fixture with corrected source paths.

  • An independent stream oracle checks 111,456 formatting/round-trip results across three floating types, narrow/wide strings, three C locales and three C++ facet configurations. Original: 79,092 mismatches; fixed GCC and Clang ASan/UBSan: zero. Another 74,304 checks with two- and four-byte C decimal separators also pass. These local sanitizer runs instrument the changed headers and oracle, with an uninstrumented static Charconv dependency.

  • Fork platform matrix: functional tests pass on Linux GCC/Clang, macOS, MinGW and MSVC 32/64. The GCC12 full sanitizer/test step passes; its coverage publishing fails because the wrapper workflow commit is absent from the pinned shallow checkout. The original libc++19 module failure was in the new test's include order; the follow-up Clang19 run passes all module, header and C++20/23 test steps on the current head. No test assertions were removed.

AI assistance: OpenAI Codex. Changes reviewed and tested locally as described above.

Format float and double with Charconv and translate its decimal point
through the active narrow or wide numpunct facet. Normalize printf's
C-locale decimal point for extended long double, whose Charconv general
precision path is not ready for this use.

Integrate the Charconv link dependency into B2, CMake and the module,
document manual linking, and add locale round-trip regression coverage.
Correct the module test's sample path and link its header-only
no-exceptions test to the new dependency.

Fixes boostorg#98

Generated-by: OpenAI Codex
Follow the existing test include order so libc++19 does not redeclare standard-library internals after import std. Preserve every locale assertion.

Generated-by: OpenAI Codex
@trestoncuzzort
trestoncuzzort marked this pull request as ready for review October 26, 2026 10:28
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.

Desynchronized C and C++ Global Locales Break boost::lexical_cast Round-Trip

1 participant