On Friday 25 June 2004 10:47, Michael Sokolov wrote:
Ahmm, but the reciprocal of an integer is not an
integer, so you are
stepping out of integer-land into floating point territory. Do you
really want to use floating point to implement integer division
(dividing an integer by an integer to get quotient and remainder)?
And how do you guarantee that the final integer result will be exact?
(I guess you convert the dividend to a float, get the reciprocal of
the divisor, which will be a float, do float multiplication, and
integerise the result, right? Are there enough bits of precision in
a float to guarantee an exact result for integer division done this
way? I doubt that, since AFAIK Alpha has usual 32-bit and 64-bit
floats, which have other things besides mantissa in those bits, but
has 64-bit integers.) And how do you get the remainder? Floating
division (whether direct or via multiplication by the reciprocal)
doesn't produce a remainder at all.
Well, if it's really an integer, you could use a fixed-point number for
the division (assume that the highest bit is the 2^(-1)bit or 2^0 if
you can get an extra bit). For this to work, you need to have access
to double the number of input bits to the multiplier for its output. I
remember seeing this before...either in my Sr. level architecture class
or the description of how my SBC-16/40 does division, neither of which
sounds right. I need to go back and figure out where I learned this
from.
Remainder is simply quotient - divisor*result, or drop the higher half
of the result and re-do the multiplication (and the resulting higher
half is the remainder).
Pat
--
Purdue University ITAP/RCS ---
http://www.itap.purdue.edu/rcs/
The Computer Refuge ---
http://computer-refuge.org