Add native __int128 casts for bignum types#527
Merged
Merged
Conversation
Expose explicit conversions from Int128 and UInt128 to compiler-native 128-bit integers when `__int128` is available. Add unit coverage for signed and unsigned casts across zero, small values, large values, and boundary limits.
kavirajk
reviewed
Jun 29, 2026
|
|
||
| #if CH_CPP_HAS_INT128 | ||
| explicit operator unsigned __int128() const { | ||
| return ((unsigned __int128)limbs[1] << 64 | limbs[0]); |
There was a problem hiding this comment.
not an expert. why not cpp style static_cast here? instead of C-style cast? Curious.
kavirajk
reviewed
Jun 29, 2026
|
|
||
| #if CH_CPP_HAS_INT128 | ||
| explicit operator __int128() const { | ||
| return (__int128)((unsigned __int128)limbs[1] << 64 | limbs[0]); |
Contributor
Author
There was a problem hiding this comment.
No specific reason, normally I stick to static_cast, however I sometimes bypass it, but only when I work with numerics and it gets too verbose. Otherwise it would be:
return static_cast<__int128>(static_cast<unsigned __int128>(limbs[1]) << 64 | limbs[0]);
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.
Expose explicit conversions from Int128 and UInt128 to compiler-native 128-bit integers when
__int128is available. Add unit coverage for signed and unsigned casts across zero, small values, large values, and boundary limits.