超过芯片组允许的最大数据类型.C++

Exceeding largest datatype allowed on chipset. C++

本文关键字:数据类型 C++ 芯片组      更新时间:2023-10-16

我有一些数学超过了c ++长数据类型。解决这个问题的最佳方法是什么?我正在嵌入式芯片组上做基本的数学+,/和*。 我在一个循环中将数字相加,然后将大数字除以。

通常,一个long(与long int相同(的大小至少为4个字节。但是,请自己检查。如果您发现long long int的字节数超过long int,并且您的值不超过long long int中可存储的最大值,请使用该值。使用此标头中的 #include <limits> 和 Use 函数来确定整数类型中可存储的最大值。

例如

#include <limits>
#include <iostream>
int main()
{
    std::cout << std::numeric_limits<int>::max() << std::endl;
    std::cout << std::numeric_limits<long int>::max() << std::endl;
    std::cout << std::numeric_limits<long long int>::max() << std::endl;
}

这在我的机器上输出以下内容:

2147483647
9223372036854775807
9223372036854775807

但是,如果您的值也超过了可以存储在long long int中的值,请使用大数字库。