Fix for incorrect (gcd -2) => -2; should give 2.
authorNeil Jerram <neil@ossau.uklinux.net>
Wed, 17 Sep 2008 20:46:40 +0000 (21:46 +0100)
committerNeil Jerram <neil@ossau.uklinux.net>
Mon, 22 Sep 2008 20:21:20 +0000 (21:21 +0100)
(reported by Bill Schottstaedt)

* libguile/numbers.c (scm_gcd): When only one arg given, use scm_abs
  to ensure that result is non-negative.

* test-suite/tests/numbers.test ("gcd"): New test, (gcd -2).

NEWS
libguile/numbers.c
test-suite/tests/numbers.test

diff --git a/NEWS b/NEWS
index c83e2d6..3e7c6df 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,7 @@ available: Guile is now always configured in "maintainer mode".
 ** Fix build issue on hppa2.0w-hp-hpux11.11 (`dirent64' and `readdir64_r')
 ** Fix misleading output from `(help rationalize)'
 ** Fix build failure on Debian hppa architecture (bad stack growth detection)
+** Fix `gcd' when called with a single, negative argument.
 
 \f
 Changes in 1.8.5 (since 1.8.4)
index 7a4d619..52dfb73 100644 (file)
@@ -1022,7 +1022,7 @@ SCM
 scm_gcd (SCM x, SCM y)
 {
   if (SCM_UNBNDP (y))
-    return SCM_UNBNDP (x) ? SCM_INUM0 : x;
+    return SCM_UNBNDP (x) ? SCM_INUM0 : scm_abs (x);
   
   if (SCM_I_INUMP (x))
     {
index b28b4ef..32627ed 100644 (file)
   (expect-fail "documented?"
     (documented? gcd))
 
+  (with-test-prefix "(n)"
+
+    (pass-if "n = -2"
+      (eqv? 2 (gcd -2))))
+
   (with-test-prefix "(0 n)"
 
     (pass-if "n = 0"