Public Group

# Astronomical numbers problem

This topic is 2594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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++

##### Share on other sites
Use Arbitrary-precision Arithmetic (some libraries are listed in the linked Wikipedia article).

##### Share on other sites
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)

##### Share on other sites

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)

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.

##### Share on other sites
try 10472057190.0 or try adding some suffix...

##### Share on other sites

try 10472057190.0 or try adding some suffix...

Good point, it does not work with decimals. Hmm... gotta try something else.

##### Share on other sites

The scope of the project demands precission, so this is the only way.
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.

##### Share on other sites
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;

##### Share on other sites
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.

##### Share on other sites
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.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
19
4. 4
5. 5
gaxio
13

• 17
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631730
• Total Posts
3001917
×