Skip to content

docs: f64 delta receivers match the producer only up to rounding - #255

Merged
zzylol merged 1 commit into
mainfrom
docs/f64-delta-rounding
Oct 29, 2026
Merged

zzylol merged 1 commit into
mainfrom
docs/f64-delta-rounding

Conversation

@zzylol

@zzylol zzylol commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Part of #250

Why

Issue #250 lists CMS / Count Sketch f64 counters: old + (new - old) can miss new by rounding. Example: old = 1.0, new = 1e-17; the delta new - old rounds to -1.0, so the receiver holds 0.0, not 1e-17. This is inherent to floating point, so it is documented as a bounded limitation, not changed.

What

  • docs/asapv1_wire_format.md §3.23: new "Exactness of a receiver" paragraph. i32/i64 receivers equal the producer exactly; f64 receivers equal it up to rounding, with the bound below.
  • DeltaCounter doc comment (src/asapv1/delta.rs) and the Deltas section of the Count-Min, Count Sketch, CountMinSketchWithHeap and CountSketchWithHeap API pages state the same.
  • Test in src/sketches/countminsketch/delta.rs; CHANGELOG entry (Docs).

How

Bound (u = 2^-53, finite values): each apply is one add rounded to nearest, off by at most u*|result|. After n applies from an equal start the cell differs by at most the sum of e_i + u*|r_i|, where e_i is how far delta i is from the producer's true change. A producer forming d_i = new - old of its own f64 cells has e_i <= u*|d_i|, giving at most 2*n*u*M; one summing updates in a separate buffer carries that buffer's error in e_i. Integer-valued f64 cells below 2^53 are exact too. The API pages say each apply adds at most u*|result| on top of the error the delta already carries. Heaps are replaced, not added, so carry no such error. Octo's emitted cell deltas are integer (count as i32) and are not affected.

Before / After

Before: nothing said a receiver may differ. After: the limitation and bound are stated and tested. No behavior change, no deletions.

Verification

  • cargo test --lib countminsketch::delta: 6 passed, including f64_receiver_differs_from_producer_within_the_documented_bound (concrete miss, plus a seeded 1000-apply sequence of mixed-magnitude, mixed-sign cell values that asserts error > 0 and within the summed bound) and integer_receiver_equals_producer_exactly.
  • cargo fmt --check, cargo clippy --all-targets with and without --features experimental: clean.

Limitations

The test sits in the Count-Min module; Count Sketch shares add_cells, so the same arithmetic applies. The bound assumes every cell, delta and sum is finite (the decoder accepts inf/NaN f64 deltas, and an add can overflow to inf).

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol
zzylol marked this pull request as ready for review October 29, 2026 00:41
@zzylol
zzylol force-pushed the docs/f64-delta-rounding branch from 7fb0552 to 39861bf Compare October 29, 2026 00:41
@zzylol
zzylol merged commit a3c08d0 into main Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant