Afficher un message
Vieux 02/07/2008, 19h43   #14
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there an algorithm for integer multiply and divide at the same time?

terminator wrote:

> On Jul 2, 7:16am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
>> Default User wrote:

[snip]
>> > In this case I am looking to make 64 bit integers perform 128 bit like
>> > multiplication/division, but I would think I could easily adapt code
>> > designed to make 32 bit integers perform 64 bit like
>> > multiplication/division. Does anyone have any simple/short code made
>> > 64 bit integers from 32 bit integers, from a time before 64 bit
>> > integers were available natively in the compiler?

[snip]
>> The tricky part is division. I have no idea how to do that efficiently.

[snip]
>
> not sure but if one splits the 128-bit product in to 64-bit digits:
>
> int64 proH,proL;
>
> then (s)he might be able to use the algorithm that has been used - for
> hundreds of years - to manually calculate the decimal division of
> numbers.I am a computer generation guy and do not remember how I used
> to divide two numbers in primary school mathematics course but
> somebody must remember it.


Well, the paper and pencil method of long division requires that you _know_
the multiplication table for one-digit numbers, i.e., you can divide
two-digit numbers by one-digit numbers provided the result has only one
digit. So using base 2^64 for the computation will not quite work. You
could use base 2^32 and use four digits.

However, even then the pencil and paper method you were taught requires a
certain degree of guesswork which has to be replaces by rigorous analysis.
Knuth has an exposition of that.


Best

Kai-Uwe Bux
  Réponse avec citation
 
Page generated in 0,05038 seconds with 9 queries