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

Large integers cause rounding errors #6

Open
cbartondock opened this issue Mar 27, 2023 · 2 comments
Open

Large integers cause rounding errors #6

cbartondock opened this issue Mar 27, 2023 · 2 comments

Comments

@cbartondock
Copy link

Same issue as here node-steam/vdf#12

Large integers (or strings that contain numerical values that get interpreted as integers) get rounded, even if they were initially intended as strings. See the following repl:

https://replit.com/@ChrisDock/Testing-node-steamvdf-for-long-strings#index.js

@p0358
Copy link
Owner

p0358 commented Mar 29, 2023

In the meantime one can use the option types: false to keep every value as a string, I'll soon look into adding some BigInt support. Just not sure if enabling it should make all numbers BigInt or only those that are too big to be represented within 48 bits of precision, probably the latter. It would be disabled by default, as BigInt could break existing code that relies on normal numbers

@cbartondock
Copy link
Author

Yet another solution might be to encode the type in the vdf. This is what I ended up doing, eg. A number 1234 gets encoder as "n1234" which is then parsed as 1234, whereas a string "1234" gets encoded as "s1234" which is parsed as "1234"

This amounts to essentially altering the vdf rules and would break in many situations where other programs are reading the vdf, but it worked perfectly for me.

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

2 participants