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

bug(json): primitive numbers greater than 14 significant digits are rounded by json.lua #384

Closed
dtfiedler opened this issue Oct 22, 2024 · 1 comment

Comments

@dtfiedler
Copy link

dtfiedler commented Oct 22, 2024

TLDR:

Lua >5.3 supports 64-bit integers, but encode_number rounds to 14 significant digits. This causes values to be unnecessarily rounded even though Lua and WASM support them.

Related to the PR in the original json.lua implementation here - rxi/json.lua#42

Example:

Spin up a process using aos and add the following Handler.

Handlers.add("test", "Get-Number", function (msg) 
  local exampleValue = 951824235837328
  ao.send({ Target = msg.From, Value = exampleValue, Data = exampleValue })
end)

Value and Data are rounded and returned as 951824235837330. If tostring() is used, the correct number (as a string) is returned.

dtfiedler added a commit to dtfiedler/json.lua that referenced this issue Oct 22, 2024
This is one approach, there are many ways to handle. But given wasm64 and lua 5.3+ support 64 bit integers more precision should be given to raw numbers when encoding.

Ref: permaweb/aos#384
dtfiedler added a commit to dtfiedler/ao that referenced this issue Oct 22, 2024
This is one approach, there are many ways to handle. But given wasm64 and lua 5.3+ support 64 bit integers more precision should be given to raw numbers when encoding.

Ref: permaweb/aos#384
@dtfiedler
Copy link
Author

Closed and replaced with permaweb/ao#1054

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

1 participant