From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: Forwarded patch for modular exponentiation support (GMP powm) Date: Tue, 10 Feb 2004 09:15:35 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <874qtzsv3c.fsf@zip.com.au> References: <87k73cng30.fsf@raven.i.defaultvalue.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1076368860 23985 80.91.224.253 (9 Feb 2004 23:21:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 9 Feb 2004 23:21:00 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Feb 10 00:20:49 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AqKhs-0008T9-00 for ; Tue, 10 Feb 2004 00:20:48 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AqKhd-0007Bs-Js for guile-devel@m.gmane.org; Mon, 09 Feb 2004 18:20:33 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AqKhD-0007Ag-Kh for guile-devel@gnu.org; Mon, 09 Feb 2004 18:20:07 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AqKgh-0006s7-Gt for guile-devel@gnu.org; Mon, 09 Feb 2004 18:20:06 -0500 Original-Received: from [61.8.0.84] (helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AqKdA-00058H-2U for guile-devel@gnu.org; Mon, 09 Feb 2004 18:15:56 -0500 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i19NFjLE014894; Tue, 10 Feb 2004 10:15:45 +1100 Original-Received: from localhost (ppp57.dyn251.pacific.net.au [203.143.251.57]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i19NFhYb015078; Tue, 10 Feb 2004 10:15:44 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1AqKcr-0001Jm-00; Tue, 10 Feb 2004 09:15:37 +1000 Original-To: Eric Hanchrow Mail-Copies-To: never In-Reply-To: <87k73cng30.fsf@raven.i.defaultvalue.org> (Rob Browning's message of "Wed, 28 Jan 2004 11:22:27 -0600") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3353 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3353 Eric Hanchrow 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