#### Archived

This topic is now archived and is closed to further replies.

# BIG numbers in C++

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

## Recommended Posts

I''m currently working with some just ENORMOUS numbers in C++ and was wondering what the best variable type to hold these things was. I also need to be able to preform division and powers on them if possible. By big, I mean BIG, and I doubt they''ll fit into a __int64 (INT64). Example of a number I''m trying to hold: 26805981360853818695407014267290429139643571279154850020847954772395047564608850860412196615063170321401855621658740149606479719346829409981973427406111042323920728690442989669867762576087086725823729986997022702618035036058892123691104934210118900606540736462419686823227751954847412991668489864300132286861367430221357039419419014825366308708932420762246187042738448113789744277741439275829083482339183483169617441630665873424148957247561392117681164669809712118583777755660288000000000000000000000000000000000000000000000000000000000000000000 Thanks, ms

##### Share on other sites
Check this out:

http://www.swox.com/gmp/

##### Share on other sites
the largest number __int64 can hold is 18,446,744,073,709,551,616 (2^64)

##### Share on other sites
quote:
Original post by mdog1234
the largest number __int64 can hold is 18,446,744,073,709,551,616 (2^64)

shouldn''t it be 2^63-1?

##### Share on other sites
Well... I''m not sure why this is in GP&T or why you didn''t search "big numbers" but...
1
2
3

If a plant cannot live according to its nature, it dies; so a man.

(princ(substitute #\Space #\0(format()"~36R"5688852237040631986030796883)))

##### Share on other sites
We did a program like this in one of my programming classes. I''m not quite sure how it''ll help, but it might at least give you an idea or something. Basically what we had was an array of a certain size, that each index held the number in that position (eg. ones, tens, etc...)
the resulting array:

1234=[1][2][3][4]

Again, I''m not sure if this will help, might take too much memory, but that''s my two cents.

It is coming...10 years in the making and It is finally coming

-Beavt8r...

##### Share on other sites
AP: The GMP download wouldn't work on any of their servers Any ideas?

Others: yeah, so __int64 definately can't hold my numbers, the biggest now is (2^165)*(3 ^220)*(5 ^66)*(11 ^330) So we're talking some DARN big numbers.

Edited to add: Beavt8r: I don't see why that wouldn't work but the number mentioned above has (I believe) 410 digits, and I really don't want to hard code that into an array...

[edited by - ms291052 on February 26, 2004 9:05:21 PM]

##### Share on other sites
Hmm, interesting... I really, really want to know why you need to use a number so big. Mind you, I''m not questioning if you need it... I''m just extremely curious to know when a number like that is needed. =)

##### Share on other sites
Just store the number in a string. You will have to add capabilities for arithmatic operations, etc. and you will have to be sure that when applying operations that the radix(base) of both numbers are the same, but it is mostly trivial.

By the way, the largest number that can be stored in N bits is (2^N)-1

RDragon

[edited by - rdragon1 on February 26, 2004 9:54:03 PM]

##### Share on other sites
wow... now i''m curious as well... i''ve needed to hold numbers bigger than _int64 can handle... if anyone gets this, please make it clear...

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633661
• Total Posts
3013220
×