Skip to content

Add native __int128 casts for bignum types#527

Merged
slabko merged 1 commit into
masterfrom
cast_to_in128
Jun 29, 2026
Merged

Add native __int128 casts for bignum types#527
slabko merged 1 commit into
masterfrom
cast_to_in128

Conversation

@slabko

@slabko slabko commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@slabko slabko requested a review from mzitnik as a code owner June 27, 2026 10:52
Comment thread clickhouse/types/bignum.h

#if CH_CPP_HAS_INT128
explicit operator unsigned __int128() const {
return ((unsigned __int128)limbs[1] << 64 | limbs[0]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not an expert. why not cpp style static_cast here? instead of C-style cast? Curious.

Comment thread clickhouse/types/bignum.h

#if CH_CPP_HAS_INT128
explicit operator __int128() const {
return (__int128)((unsigned __int128)limbs[1] << 64 | limbs[0]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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]);

@kavirajk kavirajk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. one minor clarification.

@slabko slabko merged commit e964fc8 into master Jun 29, 2026
78 checks passed
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.

2 participants