Greetings
I have a problem with numbers being too gigantical (large).
When i try to run my program, the compiler starts to complain " warning: integer constant is too large for its type. ".
The number i need to define is: 2688920000000000000000000000000000000
I had it first in "float", but after this i decided to try "double". Neither work, my program wount work if i cannot use these numbers.
So could someone let me know what to do with this.
I have it like this:
/*
float Cloud_Mass;
Cloud_Mass = 2688920000000000000000000000000000000;
*/
I use c++
Thanks for reading.
Astronomical numbers problem
Or, if this is possible, just use better units. (e.g. solar masses instead of kilograms etc).
I've worked a little in computational astronomy and have yet to see a problem where arbitrary-precision arithmetics were really neccesary (given the required precision)
So if you give us some more details about your problem, maybe we can help you better.
I've worked a little in computational astronomy and have yet to see a problem where arbitrary-precision arithmetics were really neccesary (given the required precision)
So if you give us some more details about your problem, maybe we can help you better.
Or, if this is possible, just use better units. (e.g. solar masses instead of kilograms etc).
I've worked a little in computational astronomy and have yet to see a problem where arbitrary-precision arithmetics were really neccesary (given the required precision)
So if you give us some more details about your problem, maybe we can help you better.
The scope of the project demands precission, so this is the only way. I got it to work with BigInteger library, so the problem is now solve.
Now i can make solar mass unit this way:
string S_Solar_Mass("1988920000000000000000000000000");
BigInteger Solar_Mass = stringToBigInteger(S_Solar_Mass);
Thanks alot for help people.
try 10472057190.0 or try adding some suffix...
Good point, it does not work with decimals. Hmm... gotta try something else.
It's a little hard to believe that you need more precision that a double, since 1988920000000000000000000000000 is already rounded to 6 significant figures (out of 31) which is less than a double.
The scope of the project demands precission, so this is the only way.
Yeah, there's no reason to use big ints here. You need to create double literals by adding a .0 at the end.
For example, try this.
float Cloud_Mass;
Cloud_Mass = 2688920000000000000000000000000000000.0f;
For example, try this.
float Cloud_Mass;
Cloud_Mass = 2688920000000000000000000000000000000.0f;
If you are writing a very large integer literal, make sure you put a L (for 'long long', i.e. a 64bit number) at the end of your number, like this:
345234234234234432423[color="#ff0000"]L
If it's unsigned, use UL. (for unsigned long long, also a 64bit number).
435435345345345345345435[color="#ff0000"]UL
If it's larger than 64 bits (larger than 18,446,744,073,709,551,616), you can't make it a literal. Seeing that the number is so large, you can't possibly hold it in any native C++ variable types, therefore you must already be using some sort of BigNum library, so see whether they have a macro or something as part of that library, for literals.
345234234234234432423[color="#ff0000"]L
If it's unsigned, use UL. (for unsigned long long, also a 64bit number).
435435345345345345345435[color="#ff0000"]UL
If it's larger than 64 bits (larger than 18,446,744,073,709,551,616), you can't make it a literal. Seeing that the number is so large, you can't possibly hold it in any native C++ variable types, therefore you must already be using some sort of BigNum library, so see whether they have a macro or something as part of that library, for literals.
Why was my post rated down? It answers the original question in the simplest possible manner.
The OP mentioned trying to use floats but failed due to not knowing how to declare floating point constants. All you need to do is add the appropriate suffix. All this talk about bigints is unnecessary and distracting. Unless you really need more than 53 bits of precision, but even then you need an arbitrary precision floating point type, not an integer.
Incidentally, the closest value which can be represented by a double is exactly 2688919999999999979070951376811982848.0
If for some reason you want to represent the original value exactly, you'll need a floating point type with at least 88 bits of precision.
The OP mentioned trying to use floats but failed due to not knowing how to declare floating point constants. All you need to do is add the appropriate suffix. All this talk about bigints is unnecessary and distracting. Unless you really need more than 53 bits of precision, but even then you need an arbitrary precision floating point type, not an integer.
Incidentally, the closest value which can be represented by a double is exactly 2688919999999999979070951376811982848.0
If for some reason you want to represent the original value exactly, you'll need a floating point type with at least 88 bits of precision.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement