-1

In Microsoft Visual Studio 2017 Community Edition there is the following file:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\SDK\ScopeCppSDK\SDK\include\shared\intsafe.h"

It has the following value for maximum value for a 16-byte integer:

#define UINT128_MAX 0xffffffffffffffffffffffffffffffffui128

I also found the following code in the limits file

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\SDK\ScopeCppSDK\VC\include\limits.h"

#if _INTEGRAL_MAX_BITS >= 128
    // minimum signed 128 bit value
    #define _I128_MIN   (-170141183460469231731687303715884105727i128 - 1)
    // maximum signed 128 bit value
    #define _I128_MAX     170141183460469231731687303715884105727i128
    // maximum unsigned 128 bit value
    #define _UI128_MAX    0xffffffffffffffffffffffffffffffffui128
#endif

This is grayed out as if _INTEGRAL_MAX_BITS >= 128 is not defined.

And I can't find a data type for a 128-bit integer anywhere. Can MS C or C++ handle a value that large or not? I have a new PC that should have the capability to handle math for integers that large. TIA.

Salomon Zhang
  • 1,553
  • 3
  • 23
  • 41
J. Toran
  • 157
  • 2
  • 2
  • 14
  • 2
    C and C++ don't have any upper limit for the types. Implementations will define their own limits. However, unlike gcc, there's no 128-bit integer type in MSVC even though there are a few "hints" in it (probably some remnants of prior experients or something for the future) [Can I use 128-bit integer in MSVC++?](https://stackoverflow.com/q/23775248/995714), [How to enable __int128 on Visual Studio?](https://stackoverflow.com/q/6759592/995714) – phuclv Jan 06 '19 at 06:29
  • Note that C allows for extended integer types that may be 128 bit _without_ supporting 128-bit constants. – chux - Reinstate Monica Jan 06 '19 at 09:32
  • Thx for your on-going support, chux. – J. Toran Jan 07 '19 at 08:21

1 Answers1

4

There aren't data types for 128-bit integers that work like the ones for 64-bit sizes and below. If you want them, you'll have to implement them yourself. Using GMP or boost::multiprecision is always an option.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • Thx for the quick reply. That's unfortunate. – J. Toran Jan 06 '19 at 06:21
  • There are plenty of libraries available. – David Schwartz Jan 06 '19 at 06:22
  • I would normally like to use the normal quick math of 64-bit integers, unless the numbers are too large. I'm not exactly sure how to know when it's necessary to switch to multiprecision math. Maybe by checking the number of digits? – J. Toran Jan 06 '19 at 06:27
  • 1
    if you don't need arbitrary precision, switch to gcc or Clang and use [`__int128`](https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html), or use a 128-bit fixed-width type [C++ 128/256-bit fixed size integer types](https://stackoverflow.com/q/5242819/995714), [Representing 128-bit numbers in C++](https://stackoverflow.com/q/1188939/995714), [Fastest 128 bit integer library](https://stackoverflow.com/q/3692602/995714) – phuclv Jan 06 '19 at 06:34
  • Thx for the tips, @phuclv. – J. Toran Jan 06 '19 at 06:44