Skip to content

Support wide character streams in rational output - #58

Open
trestoncuzzort wants to merge 1 commit into
boostorg:developfrom
trestoncuzzort:wide-stream-output
Open

trestoncuzzort wants to merge 1 commit into
boostorg:developfrom
trestoncuzzort:wide-stream-output

Conversation

@trestoncuzzort

Copy link
Copy Markdown

Fixes #40.

Writing boost::rational<int>(1, 3) to a wide stream currently prints 1. The output operator only accepts std::ostream, so a wide stream falls back to the rational's Boolean conversion.

Template the output operator and its temporary buffer on the destination stream's character type and traits. This reuses the existing formatting algorithm for wide streams. Update the documented signature and extend the existing tests with wide fractions, zero/nonzero values under boolalpha, width/fill, signs, internal alignment and hexadecimal prefixes.

Validation on Linux:

  • GCC 16.2.1, C++11 and C++17: the complete B2 test target passes in both modes, with 31 checks including seven runtime executions. The C++14 multiprecision test runs in C++17. The new wide cases fail 18 of 24 assertions with the original header and pass with the fix.
  • 34,560 bounded narrow/wide formatting comparisons, including classic and custom grouping locales: all mismatched before, zero mismatches after; no stream-state mismatches.
  • Clang 23, C++17, AddressSanitizer/UBSan with leak detection: all 86 cases and 1,002 assertions in rational_test pass.
  • git diff --check passes. Native Windows and 32-bit builds were not run.

OpenAI Codex assisted with investigation, implementation and tests.

Use the destination stream's character type and traits for the output
operator and its temporary buffer. Wide streams otherwise select the
Boolean conversion and print 1 for a nonzero rational.

Extend the existing output tests with wide fractions and formatting
checks, and update the documented operator signature.

Assisted-by: OpenAI Codex
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.

boost::rational serialized as wstring returns always "1"

1 participant