C++ long long int 的限制是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34842637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:26:45  来源:igfitidea点击:

What's the limit of long long int ?

c++

提问by Yash Kant

I find numeric limits of long long int insufficient. Is there any other numeric type in C++ like big integer in java?

我发现 long long int 的数字限制不够。C++ 中是否还有其他数字类型,如 Java 中的大整数?

I stumbled upon this question recently and didn't knew how to tackle it..... https://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/

我最近偶然发现了这个问题,不知道如何解决它..... https://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/

回答by encoreleeet

unsigned long long int is biggest integer type in standard C++ ( it can hold numbers from 0 to 18 446 744 073 709 551 615 ), if you want bigger ones you may need to search for some bignum libraries like this: http://www.ttmath.org/

unsigned long long int 是标准 C++ 中最大的整数类型(它可以保存从 0 到 18 446 744 073 709 551 615 的数字),如果你想要更大的数字,你可能需要搜索一些像这样的 bignum 库: http://www .ttmath.org/

回答by rbashish

Type Name - long long

类型名称 - long long

Bytes - 8

字节 - 8

Range of Values - –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

值范围 - –9,223,372,036,854,775,808 到 9,223,372,036,854,775,807

Ref: Microsoft

参考:微软

回答by Subash Chandra Manohari

You can use the C++ library <boost/multiprecision/cpp_int.hpp>for such problems.

您可以使用 C++ 库<boost/multiprecision/cpp_int.hpp>解决此类问题。

For example:

例如:

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
namespace mp = boost::multiprecision;
using namespace std;
int main()
{
    mp::cpp_int f = 1;
    for(int i = 1; i <= 100; i++)
        f *= i;
    cout << "100! = " << f << '\n';
}

This will give the output

这将给出输出

100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

To know more about C++ boost library, you can refer hereand here

要了解有关 C++ boost 库的更多信息,您可以参考这里这里