Skip to content

fix: Split and Values(step) reach the end when n × step alone overflows - #226

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/219-split-step-overflow
Oct 18, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/219-split-step-overflow

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #219

Problem

Split(step) and Values(step) stopped early, without an error, when n × step overflowed while start + n × step still fit. Each type computed the n-th boundary as start + n * step, and RangeSplitting.Steps read the overflow as the end of the domain. Int64Range.CreateFinite(-9e18, 9e18).Values(4e18) returned -9e18, -5e18, -1e18, and Split returned a last piece 10e18 wide for a 4e18 step. The same happened for DecimalRange, Float64Range and Float32Range. Int32Range was safe, because it computes in long.

Change

  • RangeSplitting.Steps takes an optional afterPrevious: the previous boundary plus one step. When at(start, n) overflows, it tries that. The boundary is null (the end of the domain) only when that overflows too, which means the boundary itself has left the domain.
  • Int64Range, DecimalRange, Float64Range and Float32Range pass checked(previous + step) or Moved(previous + step). For the integers and decimal this is exact, since previous is start + (n-1) × step. The floats keep the documented rule, Start + n × step rounded once, everywhere the product fits. Only where it doesn't does a boundary become the previous one plus the step. The doc comments and the docs/ranges.md bullet say so, and claim R41 follows the reworded sentence.
  • The temporal and NodaTime steps can't overflow on the product before the sum. A TimeSpan or Duration product is bounded by the range's width, and the day and month counts are tiny. So they are unchanged.
  • No changelog line: Split and Values(step) are new in 10.0.0, and CONTRIBUTING leaves out fixes to something new in the same release. The existing Added line already describes the behaviour.

Tests

  • RangeSplitOracleTests gains a half-domain row for the five types whose step is their own element type. It starts at MinValue / 2, steps by MaxValue / 3, and runs up to MaxValue. Every piece but the last must be one step long, and the last at most one step, for both Split and Values. Claim R39 now names this row.
  • The revert is kept as the seed split-step-product-overflow-ends-early.patch. It restores the old call sites and is caught on Int64Range, DecimalRange, Float64Range and Float32Range (dotnet run tools/oracles.cs seeds split-step-product).
  • RangeSplitTests.Split_AStepProductPastTheMaximum_StillReachesTheEnd pins the issue's examples for Int64Range (including [-9e18, -5e18, -1e18, 3e18, 7e18]), DecimalRange and Float64Range.
  • dotnet test: unit 1346, NodaTime 232, EF translation 284, conventions 395, all green.

🤖 Generated with Claude Code

From a negative start, n × step passes the element type's maximum one
step before start + n × step does. RangeSplitting.Steps read that
overflow as the end of the domain, so Int64Range, DecimalRange,
Float64Range and Float32Range dropped their last values and widened the
last piece, silently: [-9e18, 9e18].Values(4e18) stopped at -1e18.

Steps now takes the previous boundary plus the step when the product
overflows, and ends the walk only when that overflows too, which means
the boundary itself has left the domain. Int32Range already computed in
long and is unchanged; the temporal and NodaTime steps cannot overflow
before their sum does.

RangeSplitOracleTests gains a half-domain row for the five types whose
step is their own element; the seed restores the old call sites and is
caught on all four affected types.

Closes #219
Found-By: CA
Defect-Class: ALG

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred area/ranges Range unions, variants and the shape engines package/core Affects CodoMetis.ValueRanges severity/medium Inconsistency or failure in a narrow scenario labels Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ranges Range unions, variants and the shape engines bug Something isn't working package/core Affects CodoMetis.ValueRanges severity/medium Inconsistency or failure in a narrow scenario silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split(step) and Values(step) end early when n × step overflows (Int64, Decimal, Float64, Float32)

1 participant