diff options
author | Neil Jerram <neil@ossau.uklinux.net> | 2008-09-17 21:46:40 +0100 |
---|---|---|
committer | Neil Jerram <neil@ossau.uklinux.net> | 2008-09-22 21:21:20 +0100 |
commit | 1dd797921c950f0a4d396faa6d7326ec6928e771 (patch) | |
tree | 74601a98f426ae788dfa69f46e47b5f3ff61a160 | |
parent | f8c01b6f683e9a7e6962a70703cdad1f76771319 (diff) | |
download | guile-1dd797921c950f0a4d396faa6d7326ec6928e771.tar.gz |
Fix for incorrect (gcd -2) => -2; should give 2.
(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).
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | libguile/numbers.c | 2 | ||||
-rw-r--r-- | test-suite/tests/numbers.test | 5 |
3 files changed, 7 insertions, 1 deletions
@@ -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. Changes in 1.8.5 (since 1.8.4) diff --git a/libguile/numbers.c b/libguile/numbers.c index 7a4d619c8..52dfb73a8 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -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)) { diff --git a/test-suite/tests/numbers.test b/test-suite/tests/numbers.test index b28b4ef97..32627ed8c 100644 --- a/test-suite/tests/numbers.test +++ b/test-suite/tests/numbers.test @@ -1059,6 +1059,11 @@ (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" |