Search code examples
cgccg++int128

How to define INT128_MAX and INT128_MIN for __int128?


gcc has the __int128 type natively.

However, it’s not defined in limits.h. I’m mean there’re no such things as INT128_MAX or INT128_MIN

And gcc is interpreting literal constants as 64 bits integers. This means that if I write #define INT128_MIN −170141183460469231731687303715884105728 it will complain about the type telling it has truncated the value.

This is especially annoying for shifting on arrays. How to overcome this ?


Solution

  • Since you have the tag [g++], I assume you are interested in a C++ solution: the usual std::numeric_limits<__int128>::max() just works...