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.

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.

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.