Reputation: 13
I am writing a program and I need to use the mass of the Earth (5.972E24 kg) I cannot find a valid int type that fits this much data. I also need the library, so I can include it.
Upvotes: 0
Views: 951
Reputation: 1736
A double will easily hold that value:
#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
}
Floating point numbers are not stored in memory in the same fashion as integral types.
Upvotes: 4
Reputation: 1006
you should check for __int128 (gcc extention, not part of the c++ standrad) or you ca look for Arbitrary-precision arithmetic such as GMP (basically you can use numbers as big as you want, the only limit is the available memory)
Upvotes: 0