I have to keep 10^31 range decimal data in an integer data type variable.
我必须保持10 ^ 31十进制整数数据类型变量中的数据范围。
Which data type can hold this range's number?
哪个数据类型可以容纳这个范围的数字?
2 个解决方案
#1
5
No integer type defined by the C++ Standard can hold 1031. You need either
c++标准定义的整数类型不能容纳1031。你需要
- a 128-bit integer (range 1.7 × 1038). You have to resort to compiler-specific functionality for this (e.g.
__int128_t
in Clang and GCC). - 一个128位整数(范围1.7×1038)。您必须为此使用特定于编译器的功能(例如,Clang和GCC中的__int128_t)。
- or an arbitrary-precision integer class from a third-party library (checkout GMP).
- 或者第三方库中的任意精度整型类(签出GMP)。
#2
0
No fundamental type integer type is guaranteed to hold that large a range. You can find the limits in climits. They're expressed as powers of 2, but it's easy to convert, 2^n is about 10^n/3.3, so long long
will get you as far as 10^19 or so.
没有基本类型整型被保证持有那么大的a范围。你可以在陈词滥调中找到极限。他们表示为2的幂,但很容易转换,2 ^ n = 10 ^ n / 3.3,所以很久会带你到10 ^ 19左右。
No floating point type can hold that range of values with whole number precision (they're too small).
任何浮点类型都不能保持整个数字精度的值范围(它们太小了)。
You could make your own class with 14 bytes of precision (use 2 long long
variables) which supports arithmetic operations, and internally manages arithmetic carry between the two variables.
您可以用14字节的精度(使用2个长变量)创建自己的类,它支持算术运算,并在内部管理两个变量之间的算术进位。
The only alternative is to find a library which supports long, or infinite, precision.
唯一的选择是找到一个支持长或无限精度的库。
#1
5
No integer type defined by the C++ Standard can hold 1031. You need either
c++标准定义的整数类型不能容纳1031。你需要
- a 128-bit integer (range 1.7 × 1038). You have to resort to compiler-specific functionality for this (e.g.
__int128_t
in Clang and GCC). - 一个128位整数(范围1.7×1038)。您必须为此使用特定于编译器的功能(例如,Clang和GCC中的__int128_t)。
- or an arbitrary-precision integer class from a third-party library (checkout GMP).
- 或者第三方库中的任意精度整型类(签出GMP)。
#2
0
No fundamental type integer type is guaranteed to hold that large a range. You can find the limits in climits. They're expressed as powers of 2, but it's easy to convert, 2^n is about 10^n/3.3, so long long
will get you as far as 10^19 or so.
没有基本类型整型被保证持有那么大的a范围。你可以在陈词滥调中找到极限。他们表示为2的幂,但很容易转换,2 ^ n = 10 ^ n / 3.3,所以很久会带你到10 ^ 19左右。
No floating point type can hold that range of values with whole number precision (they're too small).
任何浮点类型都不能保持整个数字精度的值范围(它们太小了)。
You could make your own class with 14 bytes of precision (use 2 long long
variables) which supports arithmetic operations, and internally manages arithmetic carry between the two variables.
您可以用14字节的精度(使用2个长变量)创建自己的类,它支持算术运算,并在内部管理两个变量之间的算术进位。
The only alternative is to find a library which supports long, or infinite, precision.
唯一的选择是找到一个支持长或无限精度的库。