-2

Im seeking help in how to write an algorithm to divide two very large numbers (about 100 digits each) in C++. Id like to point out now that Im not a programmer at all!

I'm only doing this for recreational purposes so i managed to get a few free division algorithms but none of them seem to be what Im looking for! i.e., all of them still only have a precision of 16 digits!

Some people told me to get a bignum library (which I had to look up what that actually meant) and I got some arbitrary precision package from www.hvks.com, but I dont know how to actually use it!

Any help at all is greatly appreciated as I have no idea what to do!

Electrino
  • 2,636
  • 3
  • 18
  • 40
  • Did you look at the documentation? – Richard J. Ross III Apr 11 '14 at 04:41
  • 4
    The answer requires a lecture course – Ed Heal Apr 11 '14 at 04:42
  • Possible duplicate of [Algorithm for dividing very large numbers] (http://stackoverflow.com/questions/2884172/algorithm-for-dividing-very-large-numbers) – Singh Apr 11 '14 at 04:47
  • Learn how to use the arbitrary precision library first. – M.M Apr 11 '14 at 04:49
  • Incredibly unhelpful answers! I looked at the documentation & I tried to learn how to use the arbitrary precision library but as I said Im not a programmer! The user manual was written for those already in the know! I appreciate that its not an easy question to answer/help me with considering my ignorance but is there any free algorithms or literature that someone could at least point me in the right direction!? – Electrino Apr 11 '14 at 04:52

2 Answers2

4

You are going to handle some numbers with 100s of digits.

  1. You can refer some libraries like Boost::multiprecision.
    Here based on the number type that you are using, precision would be arbitrarily large (limited only by available memory), fixed at compile time (for example 50 or 100 decimal digits), or a variable controlled at run-time by member functions. The types are expression-template-enabled for better performance than naive user-defined types.

  2. Next is, GNU Multiple Precision Arithmetic Library This is a free library for arbitrary precision arithmetic and doesn't have practical limit to the precision except the ones implied by the available memory in the machine GMP runs on.

  3. Another idea is to write your own data structure to handle such numerical operations with the help of char pointer. You can keep your data as a char array and split accordingly for operations. Go with this method, if there is no suitable library for your purpose.

Hope this will help you.

Kaje
  • 851
  • 7
  • 18
1

Yeah what @EdHeal said

The answer requires a lecture course – Ed Heal

I wouldn't say this is the place to start out programming given the amount of background information on the topic that is needed. For example why is there only a precision of 16 digits? To me it seems prudent to know that before attempting this at all. Not to mention all the syntax you'd need to understand to actually write something like this in C++. Now I'm not trying to discourage you but the breadth of this question for a non-programmer requires an answer too large to give, or at least to want to even attempt. You need to at least study the basics of programming and how to actually use a library in your own program. Just showing you how to setup the linking process in an IDE could take up a page or more. Also since you didn't understand the last sentence(or at least probably didn't given you're new to programming) I think it shows a need to familiarize yourself with the world of programming before this kind of undertaking. Google is your best friend...

TerraOrbis
  • 91
  • 4
  • Thanks for the response! Just to clear something up... I do know how to code but im a definite beginner! I did a small course whilst in college, so I know the basics, but i just couldnt figure out how to write a long division algorithm. Was hoping for an easy soln but I guess its back to the books! Thanks for your help. – Electrino Apr 11 '14 at 05:50