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

How to solve the problem of large integer accuracy #106

Open
weijian-zhu opened this issue Apr 18, 2022 · 6 comments
Open

How to solve the problem of large integer accuracy #106

weijian-zhu opened this issue Apr 18, 2022 · 6 comments

Comments

@weijian-zhu
Copy link

<script src="./msgpack.js"></script>
<script>
    const { encode, decode } = msgpack5()
    var buffer = encode({ num: 86699530287996692 })
    var data = decode(buffer)
    console.log(data) // => { num: 86699530287996690  }
</script>
@simoneb
Copy link
Contributor

simoneb commented Apr 18, 2022

This is not a problem with the library, the number you're trying to represent is larger than the largest integer that JS can represent

@mcollina
Copy link
Owner

It would be amazing if this library could support BigInts

@weijian-zhu
Copy link
Author

ok,thanks you

@simoneb
Copy link
Contributor

simoneb commented Apr 18, 2022

@weijian-zhu would you like to send a PR to introduce support for BigInt perhaps?

@weijian-zhu
Copy link
Author

That sounds cool, but I still don't know enough about it to know where to start

@simoneb
Copy link
Contributor

simoneb commented Apr 18, 2022

You may want to check out how the Date codec is implemented, but I think the implementation for BigInt should be much simpler than that https://github.com/mcollina/msgpack5/blob/master/lib/codecs/DateCodec.js

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

No branches or pull requests

3 participants