I’m developing a computer program and I’m trying to work out some arithmetic algorithms for working with very large numbers. So far I have worked out a plan for addition, subtraction, and multiplication but division seems to be much more complicated. The numbers I’m working with are very large and I cannot process the entire number at once, so I have to perform these math operations piece by piece.

NOTE: For the programmers here, I am using Java which has the BigDecimal class for working with large numbers, but without going into a lengthy explanation I would like to create my own version.

I have looked at the source code for the division in Java’s MutableBigInteger to see if I could get some ideas from it, but it does a lot of things that I don’t know why it’s doing them. I’ve also read up on various division algorithms and they all seem to be about the same level of complexity. But I think once I see the process at work on an actual math problem I can work out the coding details.

I’ve worked out some very simple math problems processing only one digit at a time instead of the entire number.

For addition, this is very simple to do:

6.8 + 8.5 =
       8+5=3 (carry 1)
     6+8+1=5 (carry 1)

And the result is “1 5 3” or 15.3.

Division...not so simple apparently. Here is a basic example which I can’t seem to get to the answer “3” working with only one digit at a time:

7.2 / 2.4 = 3

I’ve tried a few methods such as dividing each digit to get an integer value and using the modulus operation for the remainder to combine with the next digit over, but I’ve only made a mess of things so far. This doesn’t seem like it should be that difficult, but it’s proving to be (I guess that’s why the division algorithms I’ve looked at are so complex)...so I think I need to enlist the help of some math gurus here. Any help on this would be greatly appreciated. Thanks. :)

  • $\begingroup$ I am not sure this is possible if you want to break up the digits of the divisor. I could very well be wrong though. $\endgroup$ – ixsetf Dec 12 '15 at 2:48
  • $\begingroup$ You will do far better to ask this question on a programming forum or to look into a book like Knuth's Seminumerical Algorithms. If you want to figure a method out for yourself, then you should first of all understand the pencil-and-paper process called long division. $\endgroup$ – Rob Arthan Dec 12 '15 at 2:50
  • $\begingroup$ @ixsetf, yes, breaking up the divisor is a tricky part that I can't quite figure out. But now I don't feel so bad for not getting it yet...this has been driving me nuts for several days. It seems like it is possible because the division for Java's MutableBigInteger does it. But I've looked at the source code for it and I just don't understand many of the things it does and the comments in the source code are not very detailed or helpful. Seeing a basic math problem worked out which shows how it is done to better understand the process would be very helpful, but I can't find anything like this. $\endgroup$ – Tekkerue Dec 12 '15 at 5:18
  • $\begingroup$ @Tekkerue Unless there is a specific reason why you need to break the divisor up digit by digit, I would suggest taking it as a whole and using the long division approach Rob Arthan mentioned. It will most likely be more efficient than any method taking individual digits of the divisor. $\endgroup$ – ixsetf Dec 12 '15 at 5:36
  • $\begingroup$ @Rob Arthan, I am on the programming forum stackoverflow & this is my first post on the math forum here, but I thought that since I'm asking to see a math problem worked out the math forum might be a better place for this question. I do understand normal long division, it's the splitting up the digits and putting them back together that is the hard part. Java's MutableBigInteger uses Knuth's "Algorithm D" and I've looked at both the source for MutableBigInteger and Knuth's book, but it's like reading the answer in another language. But seeing a real math problem worked out would really help. $\endgroup$ – Tekkerue Dec 12 '15 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.