Skip to content

Commit 1c28fed

Browse files
authored
Merge pull request #47 from jsonjoy-com/copilot/fix-46
Fix JSON decoder bug with small floats like 0.0000040357127006276845
2 parents b38580c + 639f518 commit 1c28fed

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/json/JsonDecoder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ export class JsonDecoder implements BinaryJsonDecoder {
584584
c20,
585585
c21,
586586
c22,
587+
c23,
587588
c24,
588589
);
589590
if (num !== num) throw new Error('Invalid JSON');

src/json/__tests__/JsonDecoder.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ describe('number', () => {
152152
const value = decoder.readAny();
153153
expect(value).toBe(5.6);
154154
});
155+
156+
test('small float with many digits', () => {
157+
const smallFloat = 0.0000040357127006276845;
158+
const data = Buffer.from(JSON.stringify(smallFloat), 'utf-8');
159+
decoder.reader.reset(data);
160+
const value = decoder.readAny();
161+
expect(value).toBe(smallFloat);
162+
});
155163
});
156164

157165
describe('string', () => {

0 commit comments

Comments
 (0)