C++
  Home arrow C++ arrow Large Numbers
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Large Numbers
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-07-15

    Table of Contents:
  • Large Numbers
  • The User Interface
  • File Input Lesson
  • Addition and Subtraction
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Large Numbers


    (Page 1 of 5 )

    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.

    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.

    More C++ Articles
    More By Gabor Bernat


       · Learn, learn and than again learn. Finally learn from your mistakes and change your...
     

    C++ ARTICLES

    - 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++
    - Advanced File Handling with Streams in C++
    - File Handling and Streams in C++
    - The STL String Class
    - Iostream Library and Basic I/O in C++
    - Introduction to Streams







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT