54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
;; Function To Be Tested: GCD
|
|
;;
|
|
;; Source: Guy L Steele's CLTL
|
|
;; Section: 12.4 Arithmetic Operations
|
|
;; Page: 202
|
|
;;
|
|
;; Created By: Kelly Roach
|
|
;;
|
|
;; Creation Date: July 12,1986
|
|
;;
|
|
;; Last Update: July 12,1986
|
|
;;
|
|
;; Filed As: {ERIS}<LISPCORE>CML>TEST>12-4-GCD.TEST
|
|
;;
|
|
;;
|
|
;; Syntax: (GCD &REST INTEGERS)
|
|
;;
|
|
;; Function Description:
|
|
;; This returns the greatest common divisor of all the arguments,
|
|
;; which must be integers. The result of GCD is always a non-negative
|
|
;; integer.
|
|
;; If one argument is given, its absolute value is returned.
|
|
;; If no arguments are given, GCD returns 0,
|
|
;; which is an identity for this operation.
|
|
;; For three or more arguments,
|
|
;;
|
|
;; (GCD A B C ... Z) = (GCD (GCD A B) C ... Z)
|
|
;;
|
|
;;
|
|
;; Here are some examples of the use of GCD:
|
|
;;
|
|
;; (GCD 91 -49) => 7
|
|
;; (GCD 63 -42 35) => 7
|
|
;; (GCD 5) => 5
|
|
;; (GCD -4) => 4
|
|
;; (GCD) => 0
|
|
;;
|
|
;;
|
|
;; Argument(s): INTEGERS - an integer
|
|
;;
|
|
;; Returns: an integer
|
|
;;
|
|
|
|
|
|
|
|
(do-test gcd-test
|
|
(and (eq (gcd 14 49) 7)
|
|
(eq (gcd 18 9 1) 1)
|
|
(eq (gcd -3 -9 -81) 3)
|
|
(eq (gcd 10) 10)
|
|
(zerop (gcd))))
|
|
|
|
STOP
|