私はいくつかの番号を保存する必要があるプログラムを持っています。最大のものは10^15のオーダーにすることができます。番号を保存するにはどうすればよいですか。
Gcc4.3.2コンパイラを使用しています。
私はいくつかの番号を保存する必要があるプログラムを持っています。最大のものは10^15のオーダーにすることができます。番号を保存するにはどうすればよいですか。
Gcc4.3.2コンパイラを使用しています。
long long
64ビットなので10^15に適合します。
<limits>
すべてのデータ型の制限値を確認するには、ヘッダーを使用できます。
#include <iostream>
#include <limits>
int main() {
//print maximum of various types
std::cout << "Maximum values :\n";
std::cout << "Short : " << std::numeric_limits<short>::max() << std::endl;
std::cout << "Int : " << std::numeric_limits<int>::max() << std::endl;
std::cout << "Long : " << std::numeric_limits<long>::max() << std::endl;
std::cout << "Long Long: " << std::numeric_limits<long long>::max() << std::endl;
std::cout << "Float : " << std::numeric_limits<float>::max() << std::endl;
std::cout << "Double : " << std::numeric_limits<double>::max() << std::endl;
//print minimum of various types
std::cout << "\n";
std::cout << "Minimum Values: \n";
std::cout << "Short : " << std::numeric_limits<short>::min() << std::endl;
std::cout << "Int : " << std::numeric_limits<int>::min() << std::endl;
std::cout << "Long : " << std::numeric_limits<long>::min() << std::endl;
std::cout << "Long Long: " << std::numeric_limits<long long>::min() << std::endl;
std::cout << "Float : " << std::numeric_limits<float>::min() << std::endl;
std::cout << "Double : " << std::numeric_limits<double>::min() << std::endl;
}
(私のマシンで)どの出力:
Maximum values :
Short : 32767
Int : 2147483647
Long : 2147483647
Long Long: 9223372036854775807
Float : 3.40282e+038
Double : 1.79769e+308
Minimum Values:
Short : -32768
Int : -2147483648
Long : -2147483648
Long Long: -9223372036854775808
Float : 1.17549e-038
Double : 2.22507e-308