Parse numbers as either integer or floating type #20
+79
−29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 as9007199254740992.0
, however now it is correctly parsed as9007199254740993
. Thejimp_number
function now provides a tagged union instead of a simple value, as such,jimp_int
andjimp_float
helper functions were introduced for those that don't care about those details. Currently thejimp_float
function will attempt to cast the number to adouble
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