The documentation says gcd is a "denominator." This is not true. The gcd is the "greatest common divisor" not the "greatest common denominator." There is no greatest common denominator. For example
A common denominator for 1/4 and 1/3 could be 12. But, someone else could pick 24, and another 48, and so on.
If we want a least common denominator, it is the lcm or "least common multiple" of the two denominators.
Sorry about the error in the lcm code. The two functions should be coded as follows
Code: Select all
(define (gcd_ a b)
# gcd auxilary function
(let (r (% b a))
(if (= r 0) a (gcd_ r a))))
(define-macro (gcd)
# return the greatest common divisor of its integer arguments
(apply gcd_ (args) 2))
(define (lcm_ a b)
# lcm auxilary function
(/ (* a b) (gcd_ a b)))
(define-macro (lcm)
# return the least common multiple of its integer arguments
(apply lcm_ (args) 2))