source: trunk/source/tests/ansi-tests/times-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: 684 bytes
Line 
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))))
Note: See TracBrowser for help on using the repository browser.