mpz_invert (x, 1, 0)

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Sat Mar 3 10:15:56 CET 2012


Ciao,

Il Ven, 2 Marzo 2012 11:14 am, Niels Möller ha scritto:

> Would it be an improvement to rewrite it as
>  xsize==0 || (nsize<=1 && ( (- (mp_limb_t)nsize) & (PTR(n)[0]-1))==0)

I do like Niels' proposal.

> is a correct, if almost unreadable, test ;-)

A comment can heal readability :-)

> What about documentation, if we choose Z0 == Z semantics because that
> eliminates a branch, should we document that behaviour, or leave
> inverses mod 0 undefined, in case we find some more clever conditions
> later on?

The "mod 0 == Z" semantic does not really eliminate a branch, because
current mpz_invert always return a positive inverse... but we should add a
special branch to handle the solution of "x(-1) == 1 mod 0", which answer
should be "-1"...

Again, Niels propose an elegant way out: we can let inverses mod 0
undefined. To obtain this we can keep the old library code, and patch only
the recent testing program and documentation.

I vote for this option.


What should we do with mpz_powm, and mpz_powm_ui? The code for both
functions starts with:

  n = ABSIZ(m);
  if (n == 0)
    DIVIDE_BY_ZERO;

Regards,
Marco

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



More information about the gmp-devel mailing list