From: Kevin Ryde <user42@zip.com.au>
Subject: Re: GMP code committed -- watch for bugs.
Date: Mon, 07 Apr 2003 08:50:42 +1000 [thread overview]
Message-ID: <87wui76y0t.fsf@zip.com.au> (raw)
In-Reply-To: 87he9dhoxh.fsf@raven.i.defaultvalue.org
[-- Attachment #1: Type: text/plain, Size: 542 bytes --]
Rob Browning <rlb@defaultvalue.org> 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.
[-- Attachment #2: numbers.test.gcd-n-0.diff --]
[-- Type: text/plain, Size: 425 bytes --]
--- 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"
[-- Attachment #3: numbers.c.gcd-n-0.diff --]
[-- Type: text/plain, Size: 598 bytes --]
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);
[-- Attachment #4: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2003-04-06 22:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-04 22:34 GMP code committed -- watch for bugs Rob Browning
2003-04-05 12:24 ` Marius Vollmer
2003-04-05 21:51 ` Mikael Djurfeldt
2003-04-05 22:26 ` Rob Browning
2003-04-06 7:41 ` Mikael Djurfeldt
2003-04-06 9:16 ` Mikael Djurfeldt
2003-04-06 18:43 ` Rob Browning
2003-04-06 19:12 ` Mikael Djurfeldt
2003-04-06 20:09 ` Rob Browning
2003-04-06 20:25 ` Rob Browning
2003-04-06 9:23 ` Mikael Djurfeldt
2003-04-06 20:15 ` Rob Browning
2003-04-06 22:50 ` Kevin Ryde [this message]
2003-05-10 0:22 ` GMP code committed -- watch for bugs ... gcd n 0 Kevin Ryde
2003-04-23 22:40 ` GMP code committed -- watch for bugs 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=87wui76y0t.fsf@zip.com.au \
--to=user42@zip.com.au \
/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).