unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Cc: guile-devel@gnu.org
Subject: Re: Forwarded patch for modular exponentiation support (GMP powm)
Date: Tue, 10 Feb 2004 09:15:35 +1000	[thread overview]
Message-ID: <874qtzsv3c.fsf@zip.com.au> (raw)
In-Reply-To: <87k73cng30.fsf@raven.i.defaultvalue.org> (Rob Browning's message of "Wed, 28 Jan 2004 11:22:27 -0600")

Eric Hanchrow <offby1@blarg.net> 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.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  reply	other threads:[~2004-02-09 23:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-28 17:22 Forwarded patch for modular exponentiation support (GMP powm) Rob Browning
2004-02-09 23:15 ` Kevin Ryde [this message]
2004-02-09 23:31   ` Kevin Ryde
     [not found]   ` <87llnah2hf.fsf@offby1.atm01.sea.blarg.net>
2004-02-11  1:02     ` Kevin Ryde
2004-02-11  7:00       ` Eric Hanchrow
2004-02-11 23:44         ` Kevin Ryde
2004-02-12  4:56           ` Eric Hanchrow
2004-02-14  0:23             ` Kevin Ryde
2004-02-15  0:04               ` Eric Hanchrow
2004-02-15 22:08                 ` Kevin Ryde
2004-03-20 21:20             ` Marius Vollmer
2004-03-20 21:32               ` Kevin Ryde
2004-03-21  2:28                 ` Marius Vollmer
2004-03-21 22:18                   ` Kevin Ryde
2004-03-22  0:01                     ` Eric Hanchrow
2004-03-22  0:37                       ` Kevin Ryde
2004-03-25  0:02                       ` Kevin Ryde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874qtzsv3c.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).