1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-17 03:00:21 +02:00

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).
This commit is contained in:
Neil Jerram 2008-09-17 21:46:40 +01:00
parent bed2e15fc9
commit 0bf4fe19a6
3 changed files with 7 additions and 1 deletions

1
NEWS
View file

@ -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 build issue on hppa2.0w-hp-hpux11.11 (`dirent64' and `readdir64_r')
** Fix misleading output from `(help rationalize)' ** Fix misleading output from `(help rationalize)'
** Fix build failure on Debian hppa architecture (bad stack growth detection) ** 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) Changes in 1.8.5 (since 1.8.4)

View file

@ -1022,7 +1022,7 @@ SCM
scm_gcd (SCM x, SCM y) scm_gcd (SCM x, SCM y)
{ {
if (SCM_UNBNDP (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)) if (SCM_I_INUMP (x))
{ {

View file

@ -1059,6 +1059,11 @@
(expect-fail "documented?" (expect-fail "documented?"
(documented? gcd)) (documented? gcd))
(with-test-prefix "(n)"
(pass-if "n = -2"
(eqv? 2 (gcd -2))))
(with-test-prefix "(0 n)" (with-test-prefix "(0 n)"
(pass-if "n = 0" (pass-if "n = 0"