divexact_1 and bdiv_q_1

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Thu Jan 20 17:53:32 CET 2011


Ciao Niels,

On Thu, January 20, 2011 2:09 pm, Niels Möller wrote:
> What happens if divisor is even but dividend is odd? I guess divexact_1 is
> not expected to return anything sensible in that case, but what does
> bdiv_q_1 do? Shift out and ignore low bits of the dividend? And focusing
> on the return value, does it make any sense in this case?

divexact_1 does not have a return value.
bdiv_q_1 does "shift out and ignore" as you suspect.

> Then there are two cases where the return value is a bit fishy: even d,
> and n == 1. Unless we can come up with a reasonable and useful
> definition of what the return value should be for all valid inputs, it
> would make sense to me to eliminate the return value.

I agree. That's why I asked :-)

>> The returned value is the most significant limb of the result, right?
>
> Hmm, if that's how it works, that's completely different from what I
> remembered. That convention makes some sense to me. Except that I'd
> prefer that the most significant quotient limb is not stored in memory,
> letting the caller do
>
>   qp[n-1] = mpn_bdiv_q_1(...)
>
> if desired.

I'm in doubt here... mpn_pi1_bdiv_q_1 is widely used in toom_interpolation
routines, where it is used for in-place operations, i.e. it's good to have
all limbs of the dividend overwritten by the quotient in that context.

Regards,
Marco

-- 
http://bodrato.it/software/



More information about the gmp-devel mailing list