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: GMP code committed -- watch for bugs. Date: Mon, 07 Apr 2003 08:50:42 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87wui76y0t.fsf@zip.com.au> References: <87he9dhoxh.fsf@raven.i.defaultvalue.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1049669613 15111 80.91.224.249 (6 Apr 2003 22:53:33 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 6 Apr 2003 22:53:33 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Apr 07 00:53:32 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 192J12-0003vT-00 for ; Mon, 07 Apr 2003 00:53:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 192J01-00073n-02 for guile-devel@m.gmane.org; Sun, 06 Apr 2003 18:52:30 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 192Iyu-0006N5-00 for guile-devel@gnu.org; Sun, 06 Apr 2003 18:51:20 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 192Iys-0006K1-00 for guile-devel@gnu.org; Sun, 06 Apr 2003 18:51:19 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 192Iyq-0006HA-00 for guile-devel@gnu.org; Sun, 06 Apr 2003 18:51:16 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) h36MpA0p019364 for ; Mon, 7 Apr 2003 08:51:10 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h36Mp9id002508 for ; Mon, 7 Apr 2003 08:51:09 +1000 (EST) Original-Received: from localhost (ppp57.dyn228.pacific.net.au [203.143.228.57]) by wisma.pacific.net.au (8.12.8/8.12.8) with ESMTP id h36Mp8qn029484 for ; Mon, 7 Apr 2003 08:51:08 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 192IyI-00060d-00; Mon, 07 Apr 2003 08:50:42 +1000 Original-To: guile-devel@gnu.org User-Agent: Gnus/5.090017 (Oort Gnus v0.17) Emacs/21.2 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2139 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2139 --=-=-= Rob Browning writes: > > There may well be bugs A small one in (gcd n 0), test and possible fix below. The result should of course be abs(n) but mpz_gcd_ui can't return that if it doesn't fit a ulong. > where > special casing with GMP operations could help, but it'll probably take > some good benchmarking to know for sure. ash (mentioned in the comments) would definitely benefit from the mpz 2exp functions. In gcd, it'd be nice for the inum/bignum case to share code with the bignum/inum case, like lcm does. --=-=-= Content-Disposition: attachment; filename=numbers.test.gcd-n-0.diff --- numbers.test.~1.16.~ 2003-03-26 09:11:21.000000000 +1000 +++ numbers.test 2003-04-06 15:09:42.000000000 +1000 @@ -788,6 +788,11 @@ (pass-if "n = fixnum-min - 1" (eqv? (- (- fixnum-min 1)) (gcd 0 (- fixnum-min 1))))) + (with-test-prefix "(n 0)" + + (pass-if "n = 2^128 * fixnum-max" + (eqv? (ash fixnum-max 128) (gcd (ash fixnum-max 128) 0)))) + (with-test-prefix "(1 n)" (pass-if "n = 0" --=-=-= Content-Disposition: attachment; filename=numbers.c.gcd-n-0.diff Index: numbers.c =================================================================== RCS file: /cvsroot/guile/guile/guile-core/libguile/numbers.c,v retrieving revision 1.177 diff -u -u -F^[[:alpha:]$_] -r1.177 numbers.c --- numbers.c 5 Apr 2003 19:10:22 -0000 1.177 +++ numbers.c 6 Apr 2003 22:48:02 -0000 @@ -708,6 +708,8 @@ { unsigned long result; long yy = SCM_INUM (y); + if (yy == 0) + return scm_abs (x); if (yy < 0) yy = -yy; result = mpz_gcd_ui (NULL, SCM_I_BIG_MPZ (x), yy); scm_remember_upto_here_1 (x); --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--