permaweb / ao

The ao component and tools Monorepo - 🐰 🕳️ 👈
https://cookbook_ao.arweave.dev
Other
190 stars 63 forks source link

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

Open dtfiedler opened 1 month ago

dtfiedler commented 1 month ago

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 - https://github.com/rxi/json.lua/pull/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.