Refactor integer parsing, add string to 128bit integer methods#11092
Closed
BlobCodes wants to merge 1 commit intocrystal-lang:masterfrom
Closed
Refactor integer parsing, add string to 128bit integer methods#11092BlobCodes wants to merge 1 commit intocrystal-lang:masterfrom
BlobCodes wants to merge 1 commit intocrystal-lang:masterfrom
Conversation
BlobCodes
commented
Aug 13, 2021
|
|
||
| # Same as `#to_i` but returns an `Int128` or the block's value. | ||
| def to_i128(base : Int = 10, whitespace : Bool = true, underscore : Bool = false, prefix : Bool = false, strict : Bool = true, leading_zero_is_octal : Bool = false, &block) | ||
| gen_to_ Int128, UInt128, Int128::MAX, (UInt128.new(Int128::MAX) + 1) |
Contributor
Author
There was a problem hiding this comment.
Btw I couldn't use integer literals here because crystal doesn't support that. Hopefully it will do soon, then this can look nicer.
Contributor
Author
|
Note that some checks won't run successfully because of the bad 128bit support (complaining about missing __modti3, __divti3, __udivti3, __umodti3). |
HertzDevil
reviewed
Aug 14, 2021
Comment on lines
-503
to
-506
| record ToU64Info, | ||
| value : UInt64, | ||
| negative : Bool, | ||
| invalid : Bool |
Contributor
There was a problem hiding this comment.
This can parameterize over the integer type directly:
record ToUnsignedInfo(T), value : T, # ...There is no need to switch to a NamedTuple.
Contributor
|
The performance optimizations are independent from the added 128-bit methods. The former should belong in a separate PR since they should be merged even if we never get full 128-bit integer support. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds the methods required to convert a string into Int128s and UInt128s.
Because of the internal changes to the integer parsing done in this PR, non-UInt64 numbers actually see a performance benefit when parsing aswell.
Benchmark Code
Benchmarks!
New specs were created for the 128-bit integer parsing (all ran fine).
Closes: #9516
Related: #8373