Hi and I am making a maths library which will accept infinit digits but what is the best formula a computer can understand for devision. The only one I have come across so far is long devision but is there anything better? The following is the kinda formula I am thinking of doing...

input1=8
input2=3
amount=0
answer=0
while (amount<=(input1-input2)) {
amount = amount + input2
answer = answer + 1
}
remainder = input1-amount

//------ results
remainder
floor of answer
//------

Now that I have the floor(answer) and the remainder, how do I work out the 0.666666666 which ((1/input2)*remainder) will give. Of course I am making a division algorithm so I can't use division or multiplication to get the answer. I can only use addition and subtraction. I think long devision is a slow answer but is there anything faster. By faster I mean less use of addition and subtraction but only use of addition and subtraction. Any ideas explained clearly??

Recommended Answers

All 3 Replies

First the numbers you can accept is limited to the bytes of memory the
computer has. For an algorithm for division of large numbers, google
newton raphson method.

I have tried the Russian Peasant Algorithm and although it makes a great multiplication algorithm (which I needed) I still need however a division algorithm which is to some degree easy to understand. The basic requirements to this algorithm unlike before is that the algorithm can only contain addition, subtraction and multiplication (plus loops, greater than symbols and possibly a few other minor features) but one of the things it cannot contain is the >> or << operators. Can anyone provide such an algorithm and Newtons algorithm is terribly hard to translate as it uses devision to make the devision algorithm. Thanks...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.