2

I am trying to write a code , but the place where I got stuck is that to store a big number

10^100 . this big is the number

Any suggestions

Sudhanshu Gupta
  • 2,255
  • 3
  • 36
  • 74
  • If you plan to do this yourself, have a look @ this post http://stackoverflow.com/questions/269268/how-to-implement-big-int-in-c if not, GMP is a good choise... – Fredrik Pihl Jul 28 '11 at 21:29

6 Answers6

4

Use an arbitrary precision library. A very popular one that comes to mind is GMP. It is a C library, but it has a nice C++ interface, too. It is optimized for performance, and since it is widely used, it is probably pretty robust.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
3

Redefine your units. Very rarely does a single kind of quantity vary that much. Arbitrary precision libraries are not a bad idea... But if accuracy can be sacrificed for speed, you can use floating point.

Patrick87
  • 27,682
  • 3
  • 38
  • 73
  • True. Representing "big numbers" is a trade off that follows from the application. Using Arbitrary Precision bignum is only useful if precision is above any other criteria. – Khaled Alshaya Jul 28 '11 at 21:33
2

You need a multi-precision arithmetic library.

The most popular is probably GNU MP - http://gmplib.org/

2

In C++ you can use any of the many available Big Integer Libraries

Darcara
  • 1,598
  • 1
  • 13
  • 33
2

Do you need integer precision? If so, GMP, if not, a float or double will do.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
1

Such big numbers (10^100) -- assuming with ^ you mean "to the power" -- won't fit in any of the integer types. You could use a floating point type (preferrably double here) and pow(), but you would still lose precision. If you really need integers with 100 digit or better precision, get one of the 3rd party BigInt implementations and use that. If you don't need 100 digit precision, then use double, which is part of the language(s).

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94