我正在编写程序,需要使用地球的质量(5.972E24千克)
我找不到适合这些数据的有效int类型。我还需要该库,因此可以包含它。
最佳答案
双精度值很容易保持该值:
#include <iostream>
int main()
{
double earthMass = 5.972E24;
std::cout << earthMass << std::endl; // Prints 5.972e+24
// And then some
double twoHundredEarthMass = 200 * earthMass;
std::cout << twoHundredEarthMass << std::endl; // Prints 1.1944e+27
}
浮点数不会以与整数类型相同的方式存储在内存中。
关于c++ - 整数类型大于unsigned long long,还有库吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27434096/