isar / isar/hive

int values should be stored as int64 instead of double/float64

Open
#864 1 comment 1 reaction 0 assignees View on GitHub
problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Steps to Reproduce**
Store an int above 2^53 into a Hive box. After reading the value again, it won't be the same, it will have lost some precision since Hive currently converts the value into a double for storage. On JavaScript this still gives correct behavior, since int on that platform is just a double. But on other platforms, it could be improved so that 64-bit integers could have their values preserved without custom adapter work.

**Code sample**
```
test('int', () {
final value = 0xFECDBA0987654321;
var byteData = ByteData(8)
..setFloat64(0, value.toDouble(), Endian.little);
var br = fromByteData(byteData);
expect(br.read(FrameValueType.intT), value);

byteData = ByteData(9)
..setUint8(0, FrameValueType.intT)
..setFloat64(1, value.toDouble(), Endian.little);
br = fromByteData(byteData);
expect(br.read(), value);
});

Expected: <-86208267761138911>
Actual: <-86208267761138912>
```

**Version**
- Platform: iOS
- Flutter version: 2.9.0-1.0.pre.15
- Hive version: 2.0.5

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided int test and trace from ByteData and fromByteData through FrameValueType.intT. Reproduce the precision loss for the shown value, then verify that storing and reading it preserves the exact 64-bit integer on non-JavaScript platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.