Changeset 3568


Ignore:
Timestamp:
09/04/03 00:18:18 (19 years ago)
Author:
piso
Message:

GCD

Location:
trunk/j/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/autoloads.lisp

    r3557 r3568  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: autoloads.lisp,v 1.14 2003-09-02 17:50:32 piso Exp $
     4;;; $Id: autoloads.lisp,v 1.15 2003-09-04 00:18:18 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    7474(autoload 'make-pathname)
    7575(autoload '(floor ceiling round rem mod ftruncate ffloor fceiling fround
    76             rational rationalize isqrt)
     76            rational rationalize gcd isqrt)
    7777          "numbers.lisp")
  • trunk/j/src/org/armedbear/lisp/numbers.lisp

    r3557 r3568  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: numbers.lisp,v 1.9 2003-09-02 17:49:54 piso Exp $
     4;;; $Id: numbers.lisp,v 1.10 2003-09-04 00:17:46 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    164164                               rationalize)))
    165165
     166
     167
     168(defun gcd (&rest numbers)
     169  "Returns the greatest common divisor of the arguments, which must be
     170   integers.  Gcd with no arguments is defined to be 0."
     171  (unless (every #'integerp numbers)
     172    (error 'type-error))
     173  (cond ((null numbers) 0)
     174  ((null (cdr numbers)) (abs (car numbers)))
     175  (t
     176   (do ((gcd (car numbers)
     177       (gcd-2 gcd (car rest)))
     178        (rest (cdr numbers) (cdr rest)))
     179       ((null rest) gcd)))))
    166180
    167181
Note: See TracChangeset for help on using the changeset viewer.