Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support scientific notation using native BigInt #40

Open
brandon-leapyear opened this issue Oct 31, 2020 · 0 comments · May be fixed by #41
Open

Support scientific notation using native BigInt #40

brandon-leapyear opened this issue Oct 31, 2020 · 0 comments · May be fixed by #41

Comments

@brandon-leapyear
Copy link

>>> JSON.parse('1234567834982342349e100')
1.2345678349823424e+118

>>> require('json-bigint').parse('1234567834982342349e100')
BigNumber { s: 1, e: 118, c: [ 1234567, 83498234234900 ] }

>>> require('json-bigint')({ useNativeBigInt: true }).parse('1234567834982342349e100')
Thrown:
SyntaxError: Cannot convert 1234567834982342349e100 to a BigInt

This only affects numbers in scientific notation where the string is longer than 14 characters, per

if (string.length > 15)

>>> JSON.parse('12345679e2')
1234567900

>>> require('json-bigint').parse('12345679e2')
1234567900

>>> require('json-bigint')({ useNativeBigInt: true }).parse('12345679e2')
1234567900

It would be nice if the following property held (written using the fast-check library)

fc.assert(
  fc.property(fc.jsonObject(), (v) => {
    JSONbig.parse(JSONbig.stringify(v))
  })
)

which currently fails

Thrown:
Error: Property failed after 16 tests
{ seed: -424944911, path: "15:1:0:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0", endOnFailure: true }
Counterexample: [{"":1.1102230246251565e-16}]
Shrunk 29 time(s)
Got error: SyntaxError: Cannot convert 1.1102230246251565e-16 to a BigInt
@brandon-leapyear brandon-leapyear linked a pull request Oct 31, 2020 that will close this issue
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 a pull request may close this issue.

1 participant