-
Notifications
You must be signed in to change notification settings - Fork 4
/
ceiling.lsp
176 lines (149 loc) · 4.29 KB
/
ceiling.lsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Aug 19 06:50:44 2003
;;;; Contains: Tests of CEILING
(in-package :cl-test)
(compile-and-load "numbers-aux.lsp")
(compile-and-load "ceiling-aux.lsp")
(deftest ceiling.error.1
(signals-error (ceiling) program-error)
t)
(deftest ceiling.error.2
(signals-error (ceiling 1.0 1 nil) program-error)
t)
;;;
(deftest ceiling.1
(ceiling.1-fn)
nil)
(deftest ceiling.2
(ceiling.2-fn)
nil)
(deftest ceiling.3
(ceiling.3-fn 2.0s4)
nil)
(deftest ceiling.4
(ceiling.3-fn 2.0f4)
nil)
(deftest ceiling.5
(ceiling.3-fn 2.0d4)
nil)
(deftest ceiling.6
(ceiling.3-fn 2.0l4)
nil)
(deftest ceiling.7
(ceiling.7-fn)
nil)
(deftest ceiling.8
(ceiling.8-fn)
nil)
(deftest ceiling.9
(ceiling.9-fn)
nil)
(deftest ceiling.10
(loop for x in (remove-if #'zerop *reals*)
for (q r) = (multiple-value-list (ceiling x x))
unless (and (eql q 1)
(zerop r)
(if (rationalp x) (eql r 0)
(eql r (float 0 x))))
collect x)
nil)
(deftest ceiling.11
(loop for x in (remove-if #'zerop *reals*)
for (q r) = (multiple-value-list (ceiling (- x) x))
unless (and (eql q -1)
(zerop r)
(if (rationalp x) (eql r 0)
(eql r (float 0 x))))
collect x)
nil)
(deftest ceiling.12
(let* ((radix (float-radix 1.0s0))
(rad (float radix 1.0s0))
(rrad (/ 1.0s0 rad)))
(loop for i from 1 to 1000
for x = (+ i rrad)
for (q r) = (multiple-value-list (ceiling x))
unless (and (eql q (1+ i))
(eql r (- rrad 1)))
collect (list i x q r)))
nil)
(deftest ceiling.13
(let* ((radix (float-radix 1.0s0))
(rad (float radix 1.0s0))
(rrad (/ 1.0s0 rad)))
(loop for i from 1 to 1000
for x = (- i rrad)
for (q r) = (multiple-value-list (ceiling x))
unless (and (eql q i)
(eql r (- rrad 1)))
collect (list i x q r)))
nil)
(deftest ceiling.14
(let* ((radix (float-radix 1.0f0))
(rad (float radix 1.0f0))
(rrad (/ 1.0f0 rad)))
(loop for i from 1 to 1000
for x = (+ i rrad)
for (q r) = (multiple-value-list (ceiling x))
unless (and (eql q (1+ i))
(eql r (- rrad 1)))
collect (list i x q r)))
nil)
(deftest ceiling.15
(let* ((radix (float-radix 1.0f0))
(rad (float radix 1.0f0))
(rrad (/ 1.0f0 rad)))
(loop for i from 1 to 1000
for x = (- i rrad)
for (q r) = (multiple-value-list (ceiling x))
unless (and (eql q i)
(eql r (- rrad 1)))
collect (list i x q r)))
nil)
(deftest ceiling.16
(let* ((radix (float-radix 1.0d0))
(rad (float radix 1.0d0))
(rrad (/ 1.0d0 rad)))
(loop for i from 1 to 1000
for x = (+ i rrad)
for (q r) = (multiple-value-list (ceiling x))
unless (and (eql q (1+ i))
(eql r (- rrad 1)))
collect (list i x q r)))
nil)
(deftest ceiling.17
(let* ((radix (float-radix 1.0d0))
(rad (float radix 1.0d0))
(rrad (/ 1.0d0 rad)))
(loop for i from 1 to 1000
for x = (- i rrad)
for (q r) = (multiple-value-list (ceiling x))
unless (and (eql q i)
(eql r (- rrad 1)))
collect (list i x q r)))
nil)
(deftest ceiling.18
(let* ((radix (float-radix 1.0l0))
(rad (float radix 1.0l0))
(rrad (/ 1.0l0 rad)))
(loop for i from 1 to 1000
for x = (+ i rrad)
for (q r) = (multiple-value-list (ceiling x))
unless (and (eql q (1+ i))
(eql r (- rrad 1)))
collect (list i x q r)))
nil)
(deftest ceiling.19
(let* ((radix (float-radix 1.0l0))
(rad (float radix 1.0l0))
(rrad (/ 1.0l0 rad)))
(loop for i from 1 to 1000
for x = (- i rrad)
for (q r) = (multiple-value-list (ceiling x))
unless (and (eql q i)
(eql r (- rrad 1)))
collect (list i x q r)))
nil)
;;; To add: tests that involve adding/subtracting EPSILON constants
;;; (suitably scaled) to floated integers.