[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [plt-scheme] Divisions

At 12:00 AM +0100 6/1/02, Paulo J. Matos wrote:
>Hi all,
>I'm implementing extended euclidean algorithm, I wish it to be
>fast and I need a way to compute the integer division of a by b
>and the division remainder. Is there a way to do it without 2
>divisions... (I'm counting that remainder function performs a
>Any ideas?

Well, if you subtract the quotient times the divisor from the ... 
divisee(?), you get the remainder without performing an additional 
division.  That is:

(lambda (a b)
   (let ([quotient (div a b)]
         [remainder (- a (* quotient b))])
      ... do what you want with the result ...))

Not rocket science, certainly, but the desired effect is what you 
get. Only one division.

john clements