fix lcm on 0

svn: r11194
This commit is contained in:
Matthew Flatt 2008-08-11 23:55:32 +00:00
parent 23edcfc129
commit 178c30e6e4
3 changed files with 16 additions and 5 deletions

View File

@ -291,15 +291,17 @@ otherwise.}
@defproc[(gcd [n integer?] ...) integer?]{ Returns the
@as-index{greatest common divisor} of the @scheme[n]s. If no
arguments are provided, the result is @scheme[0].
@as-index{greatest common divisor} (a non-negative number) of the
@scheme[n]s. If no arguments are provided, the result is
@scheme[0]. If all arguments are zero, the result is zero.
@examples[(gcd 10) (gcd 12 81.0)]}
@defproc[(lcm [n integer?] ...) integer?]{ Returns the
@as-index{least common multiple} of the @scheme[n]s. If no arguments
are provided, the result is @scheme[1].
@defproc[(lcm [n integer?] ...) integer?]{ Returns the @as-index{least
common multiple} (a non-negative number) of the @scheme[n]s. If no
arguments are provided, the result is @scheme[1]. If any argument is
zero, the result is zero.
@examples[(lcm 10) (lcm 3 4.0)]}

View File

@ -1119,6 +1119,9 @@
(test 5.0 gcd 5.0 -10)
(test 5.0 gcd 5.0)
(test 5.0 gcd -5.0)
(test 3 gcd 0 0 3 0)
(test 3.0 gcd 0.0 0 3 0)
(test 0 gcd 0 0 0)
(err/rt-test (gcd 5.0+0.0i 10))
(err/rt-test (gcd 5.0 10+0.0i))
(test (expt 3 37) gcd (expt 9 35) (expt 6 37))
@ -1140,6 +1143,9 @@
(test 5 lcm 5)
(test 5 lcm -5)
(test 0 lcm 123 0)
(test 0 lcm 0 0)
(test 0.0 lcm 0 0.0)
(test 0.0 lcm 0.0 0)
(test 30.0 lcm 5 6.0)
(test 6.0 lcm 6.0)
(test 6.0 lcm -6.0)

View File

@ -1086,6 +1086,9 @@ bin_lcm (Scheme_Object *n1, Scheme_Object *n2)
Scheme_Object *d, *ret;
d = scheme_bin_gcd(n1, n2);
if (scheme_is_zero(d))
return d;
ret = scheme_bin_mult(n1, scheme_bin_quotient(n2, d));