Home arrow C++ arrow Large Numbers

Large Numbers

People in general seem to dislike the concept of number arithmetic, especially if it’s all about large numbers – and here we literally mean huge ones. However, the twenty-first century is the era of computers. Our everyday lives are covered by tons of data encapsulated in computers. In this series we’re going to discuss and code operations of which Euler wouldn’t dare to dream.

Author Info:
By: Gabor Bernat
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
July 15, 2008
  1. · Large Numbers
  2. · The User Interface
  3. · File Input Lesson
  4. · Addition and Subtraction
  5. · Conclusion

print this article

Large Numbers
(Page 1 of 5 )

The presence of this invention opened up new perspectives into most of the sciences. Unfortunately, computers are machines that have their own language. The only problem is that a computer's language is different from the ones we use in our day-to-day lives.

But have no fear. You can learn this language pretty easily with a little effort, and after completing this step, the barriers in many fields of science can fall one by one.

For example, take a look at large numbers. Today we can execute calculations that exceed by far the dreams of classic mathematicians such as Euler.

And all of these are done in just fractions of a second (or even less) by a machine that occupies a small amount of space under your desk. But guess what? Despite the fact that the arrival of this age gave us some capabilities that seemed improbable years ago, the fall of the former barrier created new limitations.

In our case this occurred after the creation of the language that helps us to communicate with the computer. For example, one of the best languages, C++, has implemented data types within it, but these are of limited length and precision. Therefore, we encounter the following dilemma: what can we do when we need to make some calculations that require more precise calculations? What can we do when our calculation has a larger value than the maximum amount that can be put into an existing data type?

The answer lies in OOP (Object Oriented Programming). Thus, if you skipped some of the classes while OOP was taught, you won't fully understand this multi-part article series. However if this is the case don't hesitate to expand your knowledge. And remember as always that Google is your best friend. Keep in mind that STL will also be mandatory if you want to comprehend the coded segments of the article. Either way, the theoretical sections of this article should be of great help for anybody.

Using this method we are able to create our own data type: a specific type that knows nothing about maximum value limit or precision; the "ideal" data-type, if you will. Most current computers are 64 bit so it can represent, in the best case, 2^63 = 9,223,372,036,854,775,808 (since we assume a signed number so it's just half of 2^64). One bit is needed for the sign. That's quite a large number, but what if we need more? Obviously we need to create one for us. During this series I am going to discuss the problems that we will face upon the creation of a class and the possibilities solving it.

The article series will comprise three parts. We'll start up with the standard communication with the user of the class and the classic add and subtract methods in part one. The second part will discuss multiplication, namely the Karatsuba method. And the saga will end with dividing and other eventual extensions. I'm going to present the class already created so you can see not just the problem but the solution as well. The pure C++ code will be attached at the end of every part.

As for the practical part of a class as such in real life I can say only the following. In mathematics, cosmology and even cryptography, mankind's knowledge has evolved exponentially due the existence of these kinds of libraries, and classes that can make precise and efficient calculations of whatever complex arithmetic form.

blog comments powered by Disqus

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials