Jump to content
  • Advertisement
Sign in to follow this  
CTar

Working with high numbers( 128bit )[C++]

This topic is 4906 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

Hi, I'm looking for a way to store very big numbers, I think 128 bit would be enough, but it would be nice to be able to work with 256 bit. So how does I do this? Tried something like:
unsigned int Number : 128;



But then it says the bitfield can't be that great for this type. So is there a way to do this? I don't want to depend on compiler-specific implentations like __int64. EDIT: And if there is a way, will it be much slower than standard int(32 bit) calculations?

Share this post


Link to post
Share on other sites
Advertisement
In the past I have used libgmp which allows for rather arbitrarily sized numbers. It is quite speedy, and for most things, I doubt there will be a noticable difference.

At least when I used it [which was perhaps 3-4 years ago now] the interface was pretty unweildy. It gets the job done though, and a nice C++ wrapper for it might've been completed in the mean time.

Share this post


Link to post
Share on other sites
What kind of accuracy do you need? You could just use double-precision floating point. It will let you store almost any size number, although if you try adding one to 2.68812*10^35 nothing happens. I have to ask, too -- what are you doing where you need an integer larger than 64 bits? That does go up to about 1*10^19 you know (a couple orders of magnitude more than you need to count the number of seconds since the creation of the universe)...

Share this post


Link to post
Share on other sites
Quote:
Original post by mumpo
What kind of accuracy do you need? You could just use double-precision floating point. It will let you store almost any size number, although if you try adding one to 2.68812*10^35 nothing happens. I have to ask, too -- what are you doing where you need an integer larger than 64 bits? That does go up to about 1*10^19 you know (a couple orders of magnitude more than you need to count the number of seconds since the creation of the universe)...


Well, I need pretty much accuracy, the important thing is not to get high numbers, but have a lot of different numbers to chose from, therefore a floating point number wouldn't fit well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!