Hey guys, I've got a question about variable maximum values, not just in C++, but in programming in general.
Days ago I programed the Karatsuba algorithm, which is used for integer multiplication with big numbers, since it's faster than the traditional multiplication method. I've had problems testing it's efficiency because of the max values of long long int.
My question is: when huge calculations are done (I'm think about cryptography, NASA, university investigations, financial markets, etc). How do they solve the problem of max values? Do they use different languages that are capable of handling them? They somehow avoid the limitations while using languages like C++?
For C++ you can use a number of third party libraries. http://gmplib.org/
Other languages, such as C#, Java and D have out-of-the-box BigInteger libraries, or even better, have built-in support (for example J and maybe Haskell).
> Do they use different languages that are capable of handling them?
> They somehow avoid the limitations while using languages like C++?
The basic limitation arises from the processor, not the programming language. Mathematical operations on numbers larger than what the processor instructions can support is performed using algorithms implemented in software.
These algorithms may be available as built-ins, may be part of the standard library, may be available in a third-party library, or may be just a set of functions in the program.
Won't be an earth-shattering development if it is either accepted or rejected; though acceptance could make life a lot easier for people starting out to learn C++.
If you're looking for a challenge, you could try and write your own arithmatical operators, using an array or STL container. ;) You would, then, have truely unlimited numbers.
Thanks to all for your answers. I haven't still faced a problem which needed anything of this to be solved, but I'll keep your explanaitions and links just in case.
And IWishIKnew, looks challenging right know, maybe someday hahaha.
And IWishIKnew, looks challenging right know, maybe someday hahaha.
Personally, I would advise against doing it. It's complicated and a waste of time.
However, if you want to do it anyway, instead of using libraries such as GNU GMP or waiting for possibly a standard library in C++14 or C++17, we'll be here to help. And here's a possible start: