Skip to content

Parse numbers as either integer or floating type #20

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Guiorgy
Copy link

@Guiorgy Guiorgy commented Jun 29, 2025

When parsing numbers, first try to parse them as an integer and only if it fails, or it contains signs of being a floating number (e.g. a decimal separator), then parse them as a floating number. This reduces the potential loss of precision when parsing large numbers, for example, 9007199254740993 would be parsed as 9007199254740992.0, however now it is correctly parsed as 9007199254740993. The jimp_number function now provides a tagged union instead of a simple value, as such, jimp_int and jimp_float helper functions were introduced for those that don't care about those details. Currently the jimp_float function will attempt to cast the number to a double if it was parsed as an integer, however, jimp_int, on the other hand, will be strict about it and error out if the parsed number was a floating type instead of an integer. This can be easily amended if the behaviour is not desired.

PS. Also fixed a small typo in the README

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.

1 participant