weird results about integer division
Torbjorn Granlund
tg at gmplib.org
Tue Feb 9 20:41:17 CET 2010
jack dang <jacdang at gmail.com> writes:
The program is to store integers 0 ~ 25, five bits for each number, in a
128-bit integer. Then print them out.
However, if function *mpz_cdiv_q_2exp()* were used instead of *
mpz_fdiv_q_2exp()* or *mpz_tdiv_q_2exp()*, the results would be
25 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9
8 7 6 5 4 3 2
I am not familiar with rounding modes, and don't know how this was
implemented in the library. Guess might be a bug or I misused the library
in some way.
The expected result is
25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8
7 6 5 4 3 2 1
The results seem to be in accordance to the documented operation, as far
as I can tell.
If you need help to explain some operation, you might want to ask for
help at gmp-discuss. Then first simplify your example program to be as
simple as possible: write one example of input, do the operation for
these operands, wrote the result. Then explain what you expect.
--
Torbjörn
More information about the gmp-bugs
mailing list