Describe the bug
An existing avg metric becomes undefined when a single numeric cell is changed from 1e308 to -1e308. Both cell values are finite, and the average of the final one-row table is also finite. Defining a fresh average on exactly the same table correctly returns -1e308. This uses only TinyBase, with no browser, persistence, or synchronization.
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
- In a new directory, run
npm init -y and npm install tinybase@10.0.0.
- Save the following as
repro.mjs.
- Run
node repro.mjs.
// Run after: npm install tinybase@10.0.0
import {createMetrics, createStore} from 'tinybase';
const store = createStore().setCell('t', 'r', 'n', 1e308);
const metrics = createMetrics(store).setMetricDefinition('avg', 't', 'avg', 'n');
console.log('initial:', metrics.getMetric('avg'));
store.setCell('t', 'r', 'n', -1e308);
console.log('stored cell:', store.getCell('t', 'r', 'n'));
console.log('existing average:', metrics.getMetric('avg'));
metrics.setMetricDefinition('fresh', 't', 'avg', 'n');
console.log('fresh average:', metrics.getMetric('fresh'));
metrics.destroy();
Actual output:
initial: 1e+308
stored cell: -1e+308
existing average: undefined
fresh average: -1e+308
Expected behavior
Both the existing and fresh average should return -1e308 after setCell completes. A one-row average should equal the remaining numeric cell.
Actual behavior: the existing average is undefined, although the store contains -1e308 and a fresh average returns -1e308.
Screenshots or Videos
No response
Platform
- OS: macOS 27.0.1 (26A434), arm64
- Runtime: Node.js v24.19.0; no browser required
- TinyBase: npm release 10.0.0
- Also reproduced from source at main commit 3938658
Additional context
I searched open and closed issues with is:issue metric and is:issue overflow (the latter returned no results), and searched Discussions for metric. The closest issue is #300, fixed by #301, which concerned deleting the last numeric row and adding new rows in a transaction. This reproduction updates the same existing cell without a transaction or row deletion, and still fails in v10.0.0.
Possible cause: the average replacement shortcut in src/common/aggregators.ts evaluates add - remove, which overflows for these two finite values. Metrics then exposes the nonfinite result as undefined. The fresh metric shows that the final average itself is representable.
This report was prepared with Codex assistance; the output was reproduced against both the npm release and the source at the reported SHA.
Describe the bug
An existing avg metric becomes undefined when a single numeric cell is changed from 1e308 to -1e308. Both cell values are finite, and the average of the final one-row table is also finite. Defining a fresh average on exactly the same table correctly returns -1e308. This uses only TinyBase, with no browser, persistence, or synchronization.
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
npm init -yandnpm install tinybase@10.0.0.repro.mjs.node repro.mjs.Actual output:
Expected behavior
Both the existing and fresh average should return -1e308 after setCell completes. A one-row average should equal the remaining numeric cell.
Actual behavior: the existing average is undefined, although the store contains -1e308 and a fresh average returns -1e308.
Screenshots or Videos
No response
Platform
Additional context
I searched open and closed issues with
is:issue metricandis:issue overflow(the latter returned no results), and searched Discussions formetric. The closest issue is #300, fixed by #301, which concerned deleting the last numeric row and adding new rows in a transaction. This reproduction updates the same existing cell without a transaction or row deletion, and still fails in v10.0.0.Possible cause: the average replacement shortcut in
src/common/aggregators.tsevaluatesadd - remove, which overflows for these two finite values. Metrics then exposes the nonfinite result as undefined. The fresh metric shows that the final average itself is representable.This report was prepared with Codex assistance; the output was reproduced against both the npm release and the source at the reported SHA.