Making a 128-bit integer?

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

Recommended Posts

Hi, I know this is probably a noobish question, and probably is not possible do to the fact that processors are only 32/64 bit. But would it be possible to create a new integer that uses 128 bit, or even more if needed. Sorry if I make my self sound stupid. ^^;;

Share on other sites
Use a bignum library or a language that directly supports bignum arithmetic:

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>>>>> 2 ** 128340282366920938463463374607431768211456L

Share on other sites
Quote:
 Original post by ValeranthHi, I know this is probably a noobish question, and probably is not possible do to the fact that processors are only 32/64 bit. But would it be possible to create a new integer that uses 128 bit, or even more if needed. Sorry if I make my self sound stupid. ^^;;

The MVS long long type working on my 32-bit processor proves you wrong :)

Other than that, this covers most of it:
http://en.wikipedia.org/wiki/Bignum

Generally, you define a type that is a composite of available types.

Your 128 bit would be represented with 4 32 bit ints. Then it's just a matter of implementing operations on those types.

If you know the size in advance it's possible to have these operations implemented optimally with minimal overhead (still slower than build-in types).

Share on other sites
I will look into this, thanks guys.

Share on other sites
Still having problems figuring out how to do this. I get how its done, but I do not know how to make it. You should know I'm fairly new to C++. A example, or a link to a example would be greatly appreciated; Or a link to anything describing more then just the logic behind it.

Share on other sites
I once found this which was what I wanted, although it had a few bugs and things that needed optimising etc. I can send you my own updated version of this that also handles signed bigints etc and has other added or improved functionality, if you like.

Share on other sites
With a quick look threw, that seems to be exactly what I need. If you would be willing to give em your version, I would be much obliged. My email isn't really that hard to figure out (Ill give you a hint:Gmail) but not sure if I am allowed to post it here, so I wont.
If you would like to share emails, or if you want to post it on something like rapid-share just pm me.
Val,

Share on other sites
The Lead programmer from Chaos Studios was browsing around GameDev, and found this article. He took a look at it, and saw that it was similar to what he did. He once made a un-overflowing decimal variable, but he got too lazy to compleat it. This is what he has to say just taking a quick peak at what you wanted to do:

"It's not quite that hard. Before I made an un-overflowable decimal variable. Basically, you just need to check to see the status on the variable, if it's close to it's overflow number, you re-allocate 1 more long or double, and then start filling that next variable." - Marc

Share on other sites
Quote:
 Original post by iamtehpwnThe Lead programmer from Chaos Studios was browsing around GameDev, and found this article. He took a look at it, and saw that it was similar to what he did. He once made a un-overflowing decimal variable, but he got too lazy to compleat it. This is what he has to say just taking a quick peak at what you wanted to do: "It's not quite that hard. Before I made an un-overflowable decimal variable. Basically, you just need to check to see the status on the variable, if it's close to it's overflow number, you re-allocate 1 more long or double, and then start filling that next variable." - Marc

Also like Ive said, I know the logic behind it; I just don't know how to make it work. I remember back before 2000 I had a class with a 'Infinite' variable, that would basically do do what Marc said; It would start out as 1 byte, then more up and up the more you put in it. But sadly I have sense lost it.

Share on other sites
This is actually more fitted to assembly than C++ or C. Not only in terms of performance but also in terms of clarity. Things like carry I guess.. I remember we implemented the same thing in our microprocessor session. Well now I don't have my book neither can I recreate what was done in the lecture completely, but I think it was important to note.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• Forum Statistics

• Total Topics
634103
• Total Posts
3015539
×