Big numbers

Started by
11 comments, last by PhiberOptic 20 years, 11 months ago
How do I do if I want to use very big numbers for calculations? In Visual Studio, you could use __int64 or double, but how can I handle even bigger numbers? Do I really have to rewrite all those operators (+/-*) for an array of chars? or sumthing?
----------------------------------------------Petter Nordlander"There are only 10 kinds of people in the world. They who understand binary and those who do not"
Advertisement
Of course other people have done the hard work already so you don''t have to do it.

http://groups.yahoo.com/group/boost/files/

look for big int or big num libraries (there''s several)
__int64 is a very very big number you know.
yeah, _int64 can hold huge numbers. the max it can hold is:
2^64-1, or
18446744073709551615
also, there is another type that can hold 2^128-1 (i think),
it looks like this:
LARGE_INTEGER num;num.QuadPart=20000000000000000;... 




doh, nuts. Mmmm... donuts
My website
what if i need a number thats like 2^1024? lol i like numbers that are just obscenely large =P

isnt there a way to use an array of bytes (basicly unsigned chars) to simulate such a large number? i think ive seen it done or mentioned before =P

Bungo!

[edited by - BungoMan85 on May 17, 2003 3:14:40 PM]
Bungo!
quote:Original post by BungoMan85
what if i need a number thats like 2^1024? lol i like numbers that are just obscenely large =P

isnt there a way to use an array of bytes (basicly unsigned chars) to simulate such a large number? i think ive seen it done or mentioned before =P

Bungo!

<SPAN CLASS=editedby>[edited by - BungoMan85 on May 17, 2003 3:14:40 PM]</SPAN>



Why not use a "long double" (floating point)..
In C++, you could just write a class that holds a c-string number, but yes you will have to overload + and - as well as everything else you will use. It will be savagely slower than an actual number. At one point I started to write a class that holds an array of unsigned ints and then overloaded all the common operators using inline asm by adding corresponding elements normally and then checking status bits to see if I needed to carry anything over to the next set of corresponding elements. This is about as fast as you can get when rolling your own big numbers but I won''t bet on it being portable. It is also quite a pain to code.

no wise fish would go anywhere without a porpoise - The Mock Turtle
GNU GMP''s purpose for existence is to help those who need big numbers.


Qui fut tout, et qui ne fut rien
Invader''s Realm
using large numbers can be done by simulating them:

make an array of bytes in which u store the number in base 255 (so u use all the 8 bits in a byte)

then simulate arithmetic operations on the array.
addition and substraction is easy.
multiplication and division is harder (use the same algorithm u use calculating by hand)

at first dont start with base 256 just use base 10.

(i think the correct term is "radix" for base -> the number of digits u can use base 10-> (0 - 9) 2-> (0, 1) u get the point )

this way i caculated 2^100000 (it was very fun -> hundreds of screens of numbers)

u could make a class and overload operators.


/*ilici*/
K.. thx.


But I was hoping that there was already some predefined stuff inside msvc.. One use of such big numbers are like calculating PI as accurate as possible or other stuff where __int64 is way to small..

However, I''m gunna try writing such a class..
----------------------------------------------Petter Nordlander"There are only 10 kinds of people in the world. They who understand binary and those who do not"

This topic is closed to new replies.

Advertisement