Home arrow Development Cycles arrow Page 4 - Division of Large Numbers
DEVELOPMENT CYCLES

Division of Large Numbers


Working with large numbers (including extremely precise ones) is possible, although compilers don't acknowledge the existence of such a class/type. Writing such a type/class may seem to be a hard task; however, if we take it one step at a time, it turns out that there are many advanced techniques that make our lives easier. This situation is true with the procedure of division, on which we will focus in this article.

Author Info:
By: Gabor Bernat
Rating: 3 stars3 stars3 stars3 stars3 stars / 8
March 10, 2009
TABLE OF CONTENTS:
  1. · Division of Large Numbers
  2. · Newton's Iteration
  3. · The Code Snippet
  4. · Epilogue and Tests

print this article
SEARCH DEVARTICLES

Division of Large Numbers - Epilogue and Tests
(Page 4 of 4 )

Now the first thing you may observe about the performance of this method is that it's dependent upon how far we will take the calculation of the inverse number. If we have some easier numbers, let's say two, for which the inverse can be calculated instantly, the process will require only a very little time. Needless to say, once we move to three this process gets more complicated and it will require consistently more time.

Here are the run times first for one divided by two, then by two.



+1

+2

Division:

+0.5


And then for three:


+1

+3

Division:

+0.3333333333333333333333333333333333333333333333............


The iteration depends mainly how fast we can multiply; as we have to multiply a 5*2^i number at each step (where i stays for the current iteration number). Finally, we must say that the result won't be perfect. An error rate of 5*2^i precision exists, as after that the inverse is not calculated, so we should round the result for a perfect operation. Due to this 2/6 is not 0.5, instead you'll get 0,4999.... You get the picture. Here you have the archived source files of the entire project:



There we have it, folks, a class that can handle the basic operations with some really large or precise numbers. It may seem at first like a difficult job to do it right, but it turned out to be not too hard to accomplish. Now I invite you to implement other functions and/or operations into it. For example, why not try one that will calculate the factorial of a number if it is of the integer type? Or try calculating the square of a number; it can be resolved in the same fashion as the division using Newton's Iteration.

I want to thank you for investing time in reading this article and also encourage you to ask any question you might have here on the blog or on our friendly forum over the DevHardware. Have a great day!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
DEVELOPMENT CYCLES ARTICLES

- Division of Large Numbers
- Branch and Bound Algorithm Technique
- Dynamic Programming Algorithm Technique
- Genetic Algorithm Techniques
- Greedy Strategy as an Algorithm Technique
- Divide and Conquer Algorithm Technique
- The Backtracking Algorithm Technique
- More Pattern Matching Algorithms: B-M
- Pattern Matching Algorithms Demystified: KMP
- Coding Standards
- A Peek into the Future: Transactional Memory
- Learning About the Graph Construct using Gam...
- Learning About the Graph Construct using Gam...
- Learning About the Graph Construct using Gam...
- How to Strike a Match

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 
Support 

Developer Shed Affiliates

 




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