1 | ;;;; -*- Mode: lisp -*- |
---|
2 | ;;;; |
---|
3 | ;;;; Copyright (c) 2007, 2011 Raymond Toy |
---|
4 | ;;;; |
---|
5 | ;;;; Permission is hereby granted, free of charge, to any person |
---|
6 | ;;;; obtaining a copy of this software and associated documentation |
---|
7 | ;;;; files (the "Software"), to deal in the Software without |
---|
8 | ;;;; restriction, including without limitation the rights to use, |
---|
9 | ;;;; copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
10 | ;;;; copies of the Software, and to permit persons to whom the |
---|
11 | ;;;; Software is furnished to do so, subject to the following |
---|
12 | ;;;; conditions: |
---|
13 | ;;;; |
---|
14 | ;;;; The above copyright notice and this permission notice shall be |
---|
15 | ;;;; included in all copies or substantial portions of the Software. |
---|
16 | ;;;; |
---|
17 | ;;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
---|
18 | ;;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
---|
19 | ;;;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
---|
20 | ;;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
---|
21 | ;;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
---|
22 | ;;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
23 | ;;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
---|
24 | ;;;; OTHER DEALINGS IN THE SOFTWARE. |
---|
25 | |
---|
26 | ;; If you want all core functions to be inline (like the C++ code |
---|
27 | ;; does), add :qd-inline to *features* by enabling the following line. |
---|
28 | ;; This makes compilation much, much slower, but the resulting code |
---|
29 | ;; conses much less and is significantly faster. |
---|
30 | #+(not (and cmu x86)) |
---|
31 | (eval-when (:load-toplevel :compile-toplevel :execute) |
---|
32 | (pushnew :qd-inline *features*)) |
---|
33 | |
---|
34 | ;; To be able to inline all the functions, we need to make |
---|
35 | ;; *inline-expansion-limit* much larger. |
---|
36 | ;; |
---|
37 | ;; Not sure we really want to inline everything, but the QD C++ code |
---|
38 | ;; inlines all of the functions so we do the same. This makes CMUCL |
---|
39 | ;; take a very long time to compile the code, and the resulting |
---|
40 | ;; functions are huge. (I think div-qd is 8 KB, and sqrt-qd is a |
---|
41 | ;; whopping 30 KB!) |
---|
42 | ;; |
---|
43 | #+(and cmu qd-inline) |
---|
44 | (eval-when (:load-toplevel :compile-toplevel :execute) |
---|
45 | (setf ext:*inline-expansion-limit* 1600)) |
---|
46 | |
---|
47 | ;; |
---|
48 | ;; For all Lisps other than CMUCL, oct uses arrays to store the |
---|
49 | ;; quad-double values. This is denoted by the feature :oct-array. |
---|
50 | ;; For CMUCL, quad-doubles can be stored in a (complex |
---|
51 | ;; double-double-float) object, which is an extension in CMUCL. |
---|
52 | ;; If you want CMUCL to use an array too, add :oct-array to *features*. |
---|
53 | #-cmu |
---|
54 | (pushnew :oct-array *features*) |
---|
55 | |
---|
56 | (defpackage #:oct-internal |
---|
57 | (:use #:cl) |
---|
58 | (:nicknames #:octi) |
---|
59 | (:export #:%quad-double |
---|
60 | #:read-qd |
---|
61 | #:add-qd |
---|
62 | #:add-qd-d |
---|
63 | #:add-d-qd |
---|
64 | #:sub-qd |
---|
65 | #:sub-qd-d |
---|
66 | #:sub-d-qd |
---|
67 | #:neg-qd |
---|
68 | #:mul-qd |
---|
69 | #:mul-qd-d |
---|
70 | #:sqr-qd |
---|
71 | #:div-qd |
---|
72 | #:div-qd-d |
---|
73 | #:make-qd-d |
---|
74 | #:integer-decode-qd |
---|
75 | #:npow |
---|
76 | #:qd-0 |
---|
77 | #:qd-1 |
---|
78 | #:qd-2 |
---|
79 | #:qd-3 |
---|
80 | #:qd-parts |
---|
81 | #:+qd-one+ |
---|
82 | #:+qd-zero+ |
---|
83 | #:+qd-pi+ |
---|
84 | #:+qd-pi/2+ |
---|
85 | #:+qd-pi/4+ |
---|
86 | #:+qd-2pi+ |
---|
87 | #:+qd-log2+ |
---|
88 | ;; Functions |
---|
89 | #:hypot-qd |
---|
90 | #:abs-qd |
---|
91 | #:sqrt-qd |
---|
92 | #:log-qd |
---|
93 | #:log1p-qd |
---|
94 | #:exp-qd |
---|
95 | #:sin-qd |
---|
96 | #:cos-qd |
---|
97 | #:tan-qd |
---|
98 | #:sincos-qd |
---|
99 | #:asin-qd |
---|
100 | #:acos-qd |
---|
101 | #:atan-qd |
---|
102 | #:atan2-qd |
---|
103 | #:sinh-qd |
---|
104 | #:cosh-qd |
---|
105 | #:tanh-qd |
---|
106 | #:asinh-qd |
---|
107 | #:acosh-qd |
---|
108 | #:atanh-qd |
---|
109 | #:qd-= |
---|
110 | #:qd-> |
---|
111 | #:qd-< |
---|
112 | #:qd->= |
---|
113 | #:qd-<= |
---|
114 | #:zerop-qd |
---|
115 | #:plusp-qd |
---|
116 | #:minusp-qd |
---|
117 | #:integer-decode-qd |
---|
118 | #:decode-float-qd |
---|
119 | #:scale-float-qd |
---|
120 | #:ffloor-qd |
---|
121 | #:random-qd |
---|
122 | #:with-qd-parts |
---|
123 | #:rational-to-qd |
---|
124 | #:float-infinity-p |
---|
125 | #:float-nan-p |
---|
126 | ) |
---|
127 | #+cmu |
---|
128 | (:export #:add-qd-dd |
---|
129 | #:sub-qd-dd |
---|
130 | #:div-qd-dd |
---|
131 | #:make-qd-dd) |
---|
132 | #+cmu |
---|
133 | (:import-from #:c |
---|
134 | #:two-prod |
---|
135 | #:two-sqr) |
---|
136 | #+cmu |
---|
137 | (:import-from #:ext |
---|
138 | #:float-infinity-p |
---|
139 | #:float-nan-p |
---|
140 | #:float-trapping-nan-p |
---|
141 | #:double-double-float)) |
---|
142 | |
---|
143 | (defpackage #:net.common-lisp.oct |
---|
144 | (:use #:cl #:oct-internal) |
---|
145 | (:nicknames #:oct) |
---|
146 | (:shadow #:+ |
---|
147 | #:- |
---|
148 | #:* |
---|
149 | #:/ |
---|
150 | #:1+ |
---|
151 | #:1- |
---|
152 | #:zerop |
---|
153 | #:plusp |
---|
154 | #:minusp |
---|
155 | #:abs |
---|
156 | #:sqrt |
---|
157 | #:log |
---|
158 | #:exp |
---|
159 | #:sin |
---|
160 | #:cos |
---|
161 | #:tan |
---|
162 | #:asin |
---|
163 | #:acos |
---|
164 | #:atan |
---|
165 | #:sinh |
---|
166 | #:cosh |
---|
167 | #:tanh |
---|
168 | #:asinh |
---|
169 | #:acosh |
---|
170 | #:atanh |
---|
171 | #:expt |
---|
172 | #:= |
---|
173 | #:/= |
---|
174 | #:< |
---|
175 | #:> |
---|
176 | #:<= |
---|
177 | #:>= |
---|
178 | #:complex |
---|
179 | #:integer-decode-float |
---|
180 | #:decode-float |
---|
181 | #:scale-float |
---|
182 | #:float |
---|
183 | #:floatp |
---|
184 | #:floor |
---|
185 | #:ffloor |
---|
186 | #:ceiling |
---|
187 | #:fceiling |
---|
188 | #:truncate |
---|
189 | #:ftruncate |
---|
190 | #:round |
---|
191 | #:fround |
---|
192 | #:rem |
---|
193 | #:mod |
---|
194 | #:realpart |
---|
195 | #:imagpart |
---|
196 | #:conjugate |
---|
197 | #:float-sign |
---|
198 | #:qd-format-exp |
---|
199 | #:max |
---|
200 | #:min |
---|
201 | #:cis |
---|
202 | #:phase |
---|
203 | #:signum |
---|
204 | #:coerce |
---|
205 | #:random |
---|
206 | #:realp |
---|
207 | #:complexp |
---|
208 | #:numberp |
---|
209 | #:incf |
---|
210 | #:decf |
---|
211 | #:float-digits |
---|
212 | #:rational |
---|
213 | #:rationalize |
---|
214 | ) |
---|
215 | ;; Export types |
---|
216 | (:export #:qd-real |
---|
217 | #:qd-complex) |
---|
218 | ;; Export functions that have CL equivalents |
---|
219 | (:export #:+ |
---|
220 | #:- |
---|
221 | #:* |
---|
222 | #:/ |
---|
223 | #:1+ |
---|
224 | #:1- |
---|
225 | #:zerop |
---|
226 | #:plusp |
---|
227 | #:minusp |
---|
228 | #:abs |
---|
229 | #:sqrt |
---|
230 | #:log |
---|
231 | #:exp |
---|
232 | #:sin |
---|
233 | #:cos |
---|
234 | #:tan |
---|
235 | #:asin |
---|
236 | #:acos |
---|
237 | #:atan |
---|
238 | #:sinh |
---|
239 | #:cosh |
---|
240 | #:tanh |
---|
241 | #:asinh |
---|
242 | #:acosh |
---|
243 | #:atanh |
---|
244 | #:expt |
---|
245 | #:= |
---|
246 | #:/= |
---|
247 | #:< |
---|
248 | #:> |
---|
249 | #:<= |
---|
250 | #:>= |
---|
251 | #:complex |
---|
252 | #:integer-decode-float |
---|
253 | #:decode-float |
---|
254 | #:scale-float |
---|
255 | #:float |
---|
256 | #:floatp |
---|
257 | #:floor |
---|
258 | #:ffloor |
---|
259 | #:ceiling |
---|
260 | #:fceiling |
---|
261 | #:truncate |
---|
262 | #:ftruncate |
---|
263 | #:round |
---|
264 | #:fround |
---|
265 | #:rem |
---|
266 | #:mod |
---|
267 | #:realpart |
---|
268 | #:imagpart |
---|
269 | #:conjugate |
---|
270 | #:float-sign |
---|
271 | #:qd-format-exp |
---|
272 | #:max |
---|
273 | #:min |
---|
274 | #:cis |
---|
275 | #:phase |
---|
276 | #:signum |
---|
277 | #:coerce |
---|
278 | #:random |
---|
279 | #:realp |
---|
280 | #:complexp |
---|
281 | #:numberp |
---|
282 | #:incf |
---|
283 | #:decf |
---|
284 | #:float-digits |
---|
285 | #:rational |
---|
286 | #:rationalize) |
---|
287 | ;; Export Oct-specific functions |
---|
288 | (:export #:make-qd |
---|
289 | #:jacobi-sn |
---|
290 | #:jacobi-cn |
---|
291 | #:jacobi-dn |
---|
292 | #:elliptic-k |
---|
293 | #:elliptic-f |
---|
294 | #:elliptic-e |
---|
295 | #:elliptic-ec |
---|
296 | #:carlson-rd |
---|
297 | #:carlson-rf |
---|
298 | #:carlson-rj |
---|
299 | #:elliptic-theta-1 |
---|
300 | #:elliptic-theta-2 |
---|
301 | #:elliptic-theta-3 |
---|
302 | #:elliptic-theta-4 |
---|
303 | #:elliptic-theta) |
---|
304 | ;; Constants |
---|
305 | (:export #:+pi+ |
---|
306 | #:+pi/2+ |
---|
307 | #:+pi/4+ |
---|
308 | #:+2pi+ |
---|
309 | #:+log2+) |
---|
310 | ;; CMUCL supports infinities. |
---|
311 | #+cmu |
---|
312 | (:export #:+quad-double-float-positive-infinity+ |
---|
313 | #:+quad-double-float-negative-infinity+)) |
---|