mpz_remove_ui

Kevin Ryde user42@zip.com.au
Thu, 10 Jul 2003 09:30:41 +1000


"Andrew Friedley (CNS Student Support)" <saai@henon.cns.uni.edu> writes:
>
> May I suggest the addition of a variation of mpz_remove, mpz_remove_ui?

Sounds ok to me if Torbjorn likes it.

> As is apparent in the attached patch, the argument f is an unsigned int,
> rather than an mpz_t.

Maybe there's some optimizations we can make for small factors too.

> +mpz_remove_ui (mpz_ptr dest, mpz_srcptr src, unsigned int f)

You mean unsigned long there no doubt.

> +  if (f <= 0)
> +    DIVIDE_BY_ZERO;

An unsigned isn't often < 0.  :-)

> +  if (f == 2)

Maybe this special case could cover any power of two.  (The same for
the full mpz_remove too.)  I expect we're usually called with an odd
factor though, so it wouldn't be too important.

> +      mpz_tdiv_qr (x, rem, dest, fpow[p]);

I wonder if we can avoid calculating the quotient in the first loop.
Then say mpn_divisible_p could use the fast mpn_modexact_1_odd on
small divisors.