~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to ansi-tests/times-aux.lsp

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;-*- Mode:     Lisp -*-
 
2
;;;; Author:   Paul Dietz
 
3
;;;; Created:  Thu Aug 28 11:23:40 2003
 
4
;;;; Contains: Auxiliary functions for testing the multiplication operator *
 
5
 
 
6
(in-package :cl-test)
 
7
 
 
8
(defun integer-times (x y)
 
9
  (assert (integerp x))
 
10
  (assert (integerp y))
 
11
  (let (neg)
 
12
    (when (< x 0)
 
13
      (setq neg t x (- x)))
 
14
    (let ((result (nat-times x y)))
 
15
      (if neg (- result) result))))
 
16
 
 
17
(defun nat-times (x y)
 
18
  ;; Assumes x >= 0
 
19
  (if (= x 0)
 
20
      0
 
21
    (let ((lo (if (oddp x) y 0))
 
22
          (hi (nat-times (ash x -1) y)))
 
23
      (+ lo (+ hi hi)))))
 
24
 
 
25
(defun rat-times (x y)
 
26
  (/ (integer-times (numerator x) (numerator y))
 
27
     (integer-times (denominator x) (denominator y))))