feat: BigInt-exact multi-decimal resource aggregation (#41)#90
Merged
elizabetheonoja-art merged 1 commit intoJun 26, 2026
Conversation
…ol#41) Eliminates cumulative Number-arithmetic drift in the consumption dashboard by performing all unit conversion and summation in BigInt, with a single, explicit lossy conversion to Number at the display tail. - utils/aggregation/unitConversion.ts: exact BigInt resource factors (water 1e3, energy 3.6e6, bandwidth 1e9) + Number mirrors for the audit; convertToBase / convertToBaseApprox; toBigIntReading - utils/aggregation/ResourceUnits.ts: BigInt fixed-point value (raw + scale, default 18) with exact add/multiply/rescale, magnitude-safe toNumber, and Intl.NumberFormat toDisplay - utils/aggregation/resourceMath.ts: aggregateReadings sums exactly in BigInt, computes the Number pipeline in parallel, and logs a precision-audit warning when relative error exceeds 1e-5 (also warns past the 10k reading cap) - components/dashboard/ConsumptionPanel.tsx: total + per-resource breakdown formatted via Intl.NumberFormat (2-4 fraction digits), single lossy point, with a precision-corrected badge when drift is detected; optional 5s refresh - tests: ResourceUnits exactness, the pathological 999999999999 x 3.6e6 case, audit/cap warnings, and a deterministic 10,000-reading property test asserting relative error < 1e-5 Uses the BigInt() constructor (ES2017 target has no BigInt literals). Tests live under tests/unit since vitest collects tests/**.
elizabetheonoja-art
approved these changes
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Multi-Decimal Resource Consumption Rounding in Real-Time Aggregation (#41)
Closes #41
What's included
src/utils/aggregation/unitConversion.tswater 10³,energy 3.6×10⁶,bandwidth 10⁹) +Numbermirrors used only by the audit;convertToBase/convertToBaseApprox;toBigIntReading.src/utils/aggregation/ResourceUnits.tsraw+scale, default 18) with exactadd/multiply/rescale, a magnitude-safetoNumber(splits integer/fraction parts), andtoDisplayviaIntl.NumberFormat.src/utils/aggregation/resourceMath.tsaggregateReadingssums exactly in BigInt, computes the legacyNumberpipeline in parallel, and logs a precision-audit warning when relative error exceeds1e-5(and when the window exceeds the 10k cap).src/components/dashboard/ConsumptionPanel.tsxIntl.NumberFormat(2–4 fraction digits) — the single lossy point — with a "precision-corrected" badge when drift is detected; optional 5s refresh.tests/unit/*999,999,999,999 × 3.6×10⁶case, audit/cap warnings, and a deterministic 10,000-reading property test asserting relative error< 1e-5.