Skip to content

Support wide integral duration scalars - #254

Open
trestoncuzzort wants to merge 1 commit into
boostorg:developfrom
trestoncuzzort:fix-wide-duration-scalars
Open

trestoncuzzort wants to merge 1 commit into
boostorg:developfrom
trestoncuzzort:fix-wide-duration-scalars

Conversation

@trestoncuzzort

@trestoncuzzort trestoncuzzort commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #246.

nanoseconds(10) * uint64_t(2793555578) currently produces -15014117180 ticks instead of 27935555780. All four scalar operators narrow through int, including a second narrowing in int_adapter.

Add constrained integral overloads for *, /, *=, and /=, converting scalars to tick_type. Keep the four existing int overloads. The new overloads accept scalar values representable by tick_type; finite results must fit the duration representation and divisors must be nonzero.

The corresponding adapter operations treat raw representation values as scalar integers, including values whose bit patterns represent infinity or NaN inside an adapter. They preserve the existing special-value sign rules and negative-int behavior for unsigned adapters.

The new regression runs with microsecond and nanosecond configurations. It covers wide signed/unsigned scalars, compound-assignment results, special values, valid limit-value operations, and typed pointers to the existing int members. The duration reference documents the wider scalar contract.

Validation:

  • Full local GCC 16/C++11 and Clang 23/C++17 suites: each 165 checks and 57 runtime programs pass. The pristine suites passed 163 checks and 55 programs before edits.
  • Both new regression configurations pass ASan/UBSan and Valgrind.
  • Pinned platform validation: GCC 11/C++11, Linux Clang with ASan/UBSan, macOS Clang/C++11, and Windows MSVC/C++14 all pass the original/fixed probe, both regression configurations, and both oracle configurations.
  • A bounded tick-arithmetic oracle passes 480,000 wide-scalar comparisons; the original fails 359,172. Another 320,000 small-int comparisons have identical results before and after.
  • Seven offline dawnr kernels verify the limited exact-integer multiplication-width model and refute its narrowing control. This checks the arithmetic abstraction; the compiler and runtime tests check the C++ implementation.
  • AppVeyor: three modern lanes pass. Five legacy MSVC/C++03 lanes fail on dependency errors, with the same failed-target sets as the pristine-base build. The new scalar regressions record 76 passes across those failing lanes. These historical builds fetched dependencies separately; this is not a full AppVeyor pass.

Implemented and tested with Codex assistance.

Preserve the int overloads and accept integral scalars representable by tick_type for multiplication and division, including compound assignments. Keep raw scalar values distinct from int_adapter special values.

Fixes boostorg#246.

Generated-by: 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::posix_time::duration multiplication/division limited to int.

1 participant