fix: place 1e18 in the top regular histogram bucket#131
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Update misclassified exactly 1e18 into the +Inf overflow bucket because bucketIdx equals bucketsCount for it and the check used >=. Like every other 10^n value, 1e18 should go to the bucket with inclusive upper bound 1e18 (8.799e+17...1.000e+18). Route by value so only values strictly greater than 1e18 overflow; a plain bucketIdx > bucketsCount check is not enough because math.Log10 returns exactly 18 for values slightly above 1e18.
403cee3 to
3179fb3
Compare
|
Good catch, thanks @cubic-dev-ai — that's a real regression. For values slightly above 1e18 (e.g. Fixed by routing on the value directly: the overflow guard is now |
@vsaraikin Yep, you're right, and the fix looks correct. The original suggestion ( Your value-level check ( The Tip: get faster answers by chatting with cubic’s review copilot in the review UI |
Fixes #130.
Bug
Histogram.Updatemisclassifies exactly1e18into the+Infoverflow bucket instead of the top regular bucket.Root cause
bucketIdx = (log10(v) - e10Min) * bucketsPerDecimal. Withe10Min = -9,bucketsPerDecimal = 18andbucketsCount = 486, the value1e18givesbucketIdx = (18 - (-9)) * 18 = 486, exactly equal tobucketsCount. The overflow guard used>=:so
1e18was routed to+Infbefore reaching the regular-bucket path — which already contains the10^nedge case (idx--) that places a power of ten in the bucket whose inclusive upper bound is that power of ten. Every interior10^n(e.g.100 → 8.799e+01...1.000e+02) is placed correctly; only the maximum,1e18, was intercepted by the>=guard.Fix
Use
>so only values strictly greater than1e18overflow:1e18(the only value withbucketIdx == 486) now falls through to the regular path, where the existing10^nedge case decrementsidxto485— the8.799e+17...1.000e+18bucket.math.Inf(1)and any value above1e18still producebucketIdx > 486and remain in+Inf.Testing
Added
TestHistogramMaxPowerOfTenBoundaryasserting1e18and9.999e17land in8.799e+17...1.000e+18, while1.0001e18andmath.Inf(1)remain in1.000e+18...+Inf. It fails on the current code and passes with the fix. The full package test suite (including-race) passes unchanged.