[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forwarded patch for modular exponentiation support (GMP powm)

From: Kevin Ryde
Subject: Re: Forwarded patch for modular exponentiation support (GMP powm)
Date: Tue, 10 Feb 2004 09:15:35 +1000
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux)

Eric Hanchrow <address@hidden> writes:
> +SCM_DEFINE(scm_modular_expt, "mexpt", 3, 0, 0,

Perhaps call it modulo-expt or something, to make it vaguely match the
"modulo" function.

> +  n = coerce_to_big(n);
> +  k = coerce_to_big(k);
> +  m = coerce_to_big(m);

It might be better to make mpz_t temporaries explicitly, since they
can be cleared immediately instead of making the garbage collector
pick them up later.

> +  mpz_powm (SCM_I_BIG_MPZ (result),
> +            SCM_I_BIG_MPZ (n),
> +            SCM_I_BIG_MPZ (k),
> +            SCM_I_BIG_MPZ (m));

Don't forget to check for m==0 and throw an scm error for that.

Also, if m is negative then mpz_powm will object if there's no inverse
of n modulo m, which probably should be done as an scm error rather
than the way gmp provokes a divide by zero.  The case can be detected
by mpz_invert, though it will be wasteful to do the same as what
mpz_powm is about to do.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]