I am using the GCC built-in type __int128
for a few things in my C++ program, nothing really significant, at least not enough to justify to use BigInt library o
I would recommend against overloading operator<<
for __int128_t
. The reason is that whenever you see cout << x
for some integer type, you'd expect that all kinds of manipulators like std::hex
or std::setw
should also work. The most important guideline when overloading operators is: "do as the ints do".
As an alternative, I would recommend using a decimal_string(__int128_t)
function that you can use as cout << decimal_string(x);
in your code. For the string conversion, you can use the algorithm from any of the C-related Q&As. This makes it clear that you have special code for your 128-bit ints. Whenever the Standard Library upgrades to 128-bit support, you can drop it (and it's easy to grep
for these functions).