truncate.lsp 4.08 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Aug 20 05:13:26 2003
;;;; Contains: Tests of TRUNCATE

6

7

8 9


10 11

(deftest truncate.error.1
12 13
  (signals-error (truncate) program-error)
  t)
14 15

(deftest truncate.error.2
16 17
  (signals-error (truncate 1.0 1 nil) program-error)
  t)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

;;;

(deftest truncate.1
  (truncate.1-fn)
  nil)

(deftest truncate.2
  (truncate.2-fn)
  nil)

(deftest truncate.3
  (truncate.3-fn 2.0s4)
  nil)

(deftest truncate.4
  (truncate.3-fn 2.0f4)
  nil)

(deftest truncate.5
  (truncate.3-fn 2.0d4)
  nil)

(deftest truncate.6
  (truncate.3-fn 2.0l4)
  nil)

(deftest truncate.7
  (truncate.7-fn)
  nil)

(deftest truncate.8
  (truncate.8-fn)
  nil)

(deftest truncate.9
  (truncate.9-fn)
  nil)

(deftest truncate.10
  (loop for x in (remove-if #'zerop *reals*)
sds's avatar
sds committed
59 60 61 62 63 64
        for (q r) = (multiple-value-list (truncate x x))
        unless (and (eql q 1)
                    (zerop r)
                    (if (rationalp x) (eql r 0)
                      (eql r (float 0 x))))
        collect x)
65 66 67 68
  nil)

(deftest truncate.11
  (loop for x in (remove-if #'zerop *reals*)
sds's avatar
sds committed
69 70 71 72 73 74
        for (q r) = (multiple-value-list (truncate (- x) x))
        unless (and (eql q -1)
                    (zerop r)
                    (if (rationalp x) (eql r 0)
                      (eql r (float 0 x))))
        collect x)
75 76 77 78
  nil)

(deftest truncate.12
  (let* ((radix (float-radix 1.0s0))
sds's avatar
sds committed
79 80
         (rad (float radix 1.0s0))
         (rrad (/ 1.0s0 rad)))
81
    (loop for i from 1 to 1000
sds's avatar
sds committed
82 83 84 85 86
          for x = (+ i rrad)
          for (q r) = (multiple-value-list (truncate x))
          unless (and (eql q i)
                      (eql r rrad))
          collect (list i x q r)))
87 88 89 90
  nil)

(deftest truncate.13
  (let* ((radix (float-radix 1.0s0))
sds's avatar
sds committed
91 92
         (rad (float radix 1.0s0))
         (rrad (/ 1.0s0 rad)))
93
    (loop for i from 1 to 1000
sds's avatar
sds committed
94 95 96 97 98
          for x = (- i rrad)
          for (q r) = (multiple-value-list (truncate x))
          unless (and (eql q (1- i))
                      (eql r rrad))
          collect (list i x q r)))
99 100 101 102
  nil)

(deftest truncate.14
  (let* ((radix (float-radix 1.0f0))
sds's avatar
sds committed
103 104
         (rad (float radix 1.0f0))
         (rrad (/ 1.0f0 rad)))
105
    (loop for i from 1 to 1000
sds's avatar
sds committed
106 107 108 109 110
          for x = (+ i rrad)
          for (q r) = (multiple-value-list (truncate x))
          unless (and (eql q i)
                      (eql r rrad))
          collect (list i x q r)))
111 112 113 114
  nil)

(deftest truncate.15
  (let* ((radix (float-radix 1.0f0))
sds's avatar
sds committed
115 116
         (rad (float radix 1.0f0))
         (rrad (/ 1.0f0 rad)))
117
    (loop for i from 1 to 1000
sds's avatar
sds committed
118 119 120 121 122
          for x = (- i rrad)
          for (q r) = (multiple-value-list (truncate x))
          unless (and (eql q (1- i))
                      (eql r rrad))
          collect (list i x q r)))
123 124 125 126
  nil)

(deftest truncate.16
  (let* ((radix (float-radix 1.0d0))
sds's avatar
sds committed
127 128
         (rad (float radix 1.0d0))
         (rrad (/ 1.0d0 rad)))
129
    (loop for i from 1 to 1000
sds's avatar
sds committed
130 131 132 133 134
          for x = (+ i rrad)
          for (q r) = (multiple-value-list (truncate x))
          unless (and (eql q i)
                      (eql r rrad))
          collect (list i x q r)))
135 136 137 138
  nil)

(deftest truncate.17
  (let* ((radix (float-radix 1.0d0))
sds's avatar
sds committed
139 140
         (rad (float radix 1.0d0))
         (rrad (/ 1.0d0 rad)))
141
    (loop for i from 1 to 1000
sds's avatar
sds committed
142 143 144 145 146
          for x = (- i rrad)
          for (q r) = (multiple-value-list (truncate x))
          unless (and (eql q (1- i))
                      (eql r rrad))
          collect (list i x q r)))
147 148 149 150
  nil)

(deftest truncate.18
  (let* ((radix (float-radix 1.0l0))
sds's avatar
sds committed
151 152
         (rad (float radix 1.0l0))
         (rrad (/ 1.0l0 rad)))
153
    (loop for i from 1 to 1000
sds's avatar
sds committed
154 155 156 157 158
          for x = (+ i rrad)
          for (q r) = (multiple-value-list (truncate x))
          unless (and (eql q i)
                      (eql r rrad))
          collect (list i x q r)))
159 160 161 162
  nil)

(deftest truncate.19
  (let* ((radix (float-radix 1.0l0))
sds's avatar
sds committed
163 164
         (rad (float radix 1.0l0))
         (rrad (/ 1.0l0 rad)))
165
    (loop for i from 1 to 1000
sds's avatar
sds committed
166 167 168 169 170
          for x = (- i rrad)
          for (q r) = (multiple-value-list (truncate x))
          unless (and (eql q (1- i))
                      (eql r rrad))
          collect (list i x q r)))
171
  nil)