Jump to content
  • Advertisement

Archived

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

ms291052

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Check this out:

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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!