Skip to content

feat: BigInt-exact multi-decimal resource aggregation (#41)#90

Merged
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
real-venus:feat/bigint-resource-aggregation
Jun 26, 2026
Merged

feat: BigInt-exact multi-decimal resource aggregation (#41)#90
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
real-venus:feat/bigint-resource-aggregation

Conversation

@real-venus

Copy link
Copy Markdown
Contributor

Multi-Decimal Resource Consumption Rounding in Real-Time Aggregation (#41)

Closes #41

What's included

File Responsibility
src/utils/aggregation/unitConversion.ts Exact BigInt resource factors (water 10³, energy 3.6×10⁶, bandwidth 10⁹) + Number mirrors used only by the audit; convertToBase / convertToBaseApprox; toBigIntReading.
src/utils/aggregation/ResourceUnits.ts BigInt fixed-point value (raw + scale, default 18) with exact add/multiply/rescale, a magnitude-safe toNumber (splits integer/fraction parts), and toDisplay via Intl.NumberFormat.
src/utils/aggregation/resourceMath.ts aggregateReadings sums exactly in BigInt, computes the legacy Number pipeline in parallel, and logs a precision-audit warning when relative error exceeds 1e-5 (and when the window exceeds the 10k cap).
src/components/dashboard/ConsumptionPanel.tsx Total + per-resource breakdown formatted with Intl.NumberFormat (2–4 fraction digits) — the single lossy point — with a "precision-corrected" badge when drift is detected; optional 5s refresh.
tests/unit/* ResourceUnits exactness, the pathological 999,999,999,999 × 3.6×10⁶ case, audit/cap warnings, and a deterministic 10,000-reading property test asserting relative error < 1e-5.

…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 elizabetheonoja-art merged commit 4c1e6a6 into Utility-Protocol:main Jun 26, 2026
4 checks passed
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.

Multi-Decimal Resource Consumption Rounding in Real-Time Dashboard Aggregation

2 participants