diff --git a/NEWS b/NEWS index d5e451039..f4ca739e3 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,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 2c004f556..2dbc917df 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"