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

fix(json): modify json.lua to support larger numbers #1053

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dtfiedler
Copy link
Contributor

@dtfiedler dtfiedler commented 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.

Fixes #1054

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
return string.format("%.0f", val)
else
-- Decimals: use the 'g' format to print floating point with precision, up to 14 significant digits
return string.format("%.14g", val)
Copy link
Member

@TillaTheHun0 TillaTheHun0 Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be .20g based on this comment. ao uses a compilation of Lua 5.3 which introduced the 64 bit integers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep that would work. will make the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified - 2c8aa83

Lua 5.3 supports 64 bit integers, which shouldn't need to be converted to strings. Floating point numbers will be rounded to 20 sig digits will be rounded.
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 this pull request may close these issues.

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