1

I was wondering if there might not be a class that would allow as much accuracy as there is memory. With overloaded operators in order to do arithmetic on it as if it was a normal number.

Ex:

BigNumber num;

num = 8;
for(int i = 0; i < 5000000; ++i)
{
   num *= num;
}

Thanks

jmasterx
  • 52,639
  • 96
  • 311
  • 557
  • 64 bit integers are not big enough for you ? – Paul R Feb 05 '11 at 15:48
  • 5
    @Paul, There are plenty of applications where 64-bit integers are insufficient. – bdonlan Feb 05 '11 at 15:56
  • @bdonlan: indeed, but the question says "as much accuracy as there is memory", which although is ambiguous, I take to mean that if you have a 64 bit address space he would want 64 bit integers. And the example above suggests that 5000000 would be considered "big". But maybe I misunderstood the question ? – Paul R Feb 05 '11 at 17:01
  • 3
    @Paul R: the example suggests that 8 to the power of 5000000 is a big number – Eugen Constantin Dinca Feb 05 '11 at 17:14
  • @Paul what I meant was, an int occupies 4 bytes, and so I might want a number which consumes 1GB of ram. – jmasterx Feb 05 '11 at 18:29
  • @Milo: OK - I see now - so you just want a BigNum library that supports very large integer widths. However since there are only something like 10^80 atoms in the universe I'm not sure why you'd want integers that are 8 G bits in width, but I guess you have your reasons.. – Paul R Feb 05 '11 at 19:13

1 Answers1

6

There are plenty libraries for that, like GMP (it provides also a C++ interface) or cbignum.

You'll probably find as many libraries of this kind as you wish.

peoro
  • 25,562
  • 20
  • 98
  • 150