source: trunk/source/tests/ansi-tests/gcd-aux.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 11 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 582 bytes
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Wed Sep  3 06:57:22 2003
4;;;; Contains: Aux. functions for testing GCD
5
6(in-package :cl-test)
7
8(defun my-gcd (x y)
9  (cond
10   ((< x 0)
11    (my-gcd (- x) y))
12   ((< y 0)
13    (my-gcd x (- y)))
14   ((<= x y)
15    (my-gcd* x y))
16   (t
17    (my-gcd* y x))))
18
19(defun my-gcd* (x y)
20  ;;; 0 <= x <= y
21  (loop
22   (when (zerop x) (return y))
23   (psetq x (mod y x)
24          y x)))
25
26(defun my-lcm (x y)
27  (when (< x 0) (setf x (- x)))
28  (when (< y 0) (setf y (- y)))
29  (if (or (= x 0) (= y 0))
30      0
31    (/ (* x y) (my-gcd x y))))
32
33
34 
Note: See TracBrowser for help on using the repository browser.