Chronology Current Month Current Thread Current Date
[Year List] [Month List (current year)] [Date Index] [Thread Index] [Thread Prev] [Thread Next] [Date Prev] [Date Next]

[Phys-L] Division via subtractions



Division of positive numbers by positive numbers can be done by
consecutive subtractions. But this is too tedious for humans, unless
numbers are small. To divide a number A by a number B (to find C=A/B)
proceed as follows:

1) Set your counter of subtractions to zero (k=0). Also make initial
R=A.
2) Subtract B from R (R=R-B). If the result is negative then the answer
is C=k+B/A. Go to 6 below.
3) If the result is zero then C is integer (C=k). Stop.
4) If the result is positive then increment the counter (k=k+1).
5) Go back to 2

6) What should one do with a fractional part of the answer, such as
6/17? It depends on the desired accuracy. The easiest case is to ignore
the fraction; that is usually OK for a very large A. But suppose one
wants additional decimal digits, for example, four of them? In that
case multiply the remainder by 100000 and divide the result by B in the
same way as above. The integer part of that second division would
provide the desirable digits (after the decimal point).

I suppose that a similar algorithm can be specified for situations in
which one of the two numbers, either A or B, is negative, or when
initial numbers are allowed to be real (or complex, if you want). But
here is a pedagogical question. What is better: to start with a simple
case (when A and B are positive integers) or is it better to start with
a more general case (when A and B are real)?

P.S. What follows is a True Basic code for finding the integer part of
A/B (when A and B are real numbers).
Ludwik Kowalski

program divide
input prompt "enter the nominator A ":A
input prompt "enter the denominator B ":B
if (B=0) then
print "Negative B is meaningless."
stop
end if
let test1=sgn(A)
let test2=sgn(B)
if (test1=1 and test2=1) or (test1=0 and test2=0) then
let factor=1
else
let factor=-1 ! the result will be negative
end if
let A=abs(A)
let B=abs(B)
let k=0
let R=A
!
do ! infinite loop
let R=R-B
if R=0 then
let Cint=k+1
print"A/B is integer = ";factor*Cint
stop
else if R<0 then
exit do ! exit from the loop
else
let k=k+1
end if
loop
print "the integer part of A/B is ";factor*Cint
end