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 | #+cmu |
---|
216 | (:shadow ext:float-nan-p) |
---|
217 | ;; Export types |
---|
218 | (:export #:qd-real |
---|
219 | #:qd-complex) |
---|
220 | ;; Export functions that have CL equivalents |
---|
221 | (:export #:+ |
---|
222 | #:- |
---|
223 | #:* |
---|
224 | #:/ |
---|
225 | #:1+ |
---|
226 | #:1- |
---|
227 | #:zerop |
---|
228 | #:plusp |
---|
229 | #:minusp |
---|
230 | #:abs |
---|
231 | #:sqrt |
---|
232 | #:log |
---|
233 | #:exp |
---|
234 | #:sin |
---|
235 | #:cos |
---|
236 | #:tan |
---|
237 | #:asin |
---|
238 | #:acos |
---|
239 | #:atan |
---|
240 | #:sinh |
---|
241 | #:cosh |
---|
242 | #:tanh |
---|
243 | #:asinh |
---|
244 | #:acosh |
---|
245 | #:atanh |
---|
246 | #:expt |
---|
247 | #:= |
---|
248 | #:/= |
---|
249 | #:< |
---|
250 | #:> |
---|
251 | #:<= |
---|
252 | #:>= |
---|
253 | #:complex |
---|
254 | #:integer-decode-float |
---|
255 | #:decode-float |
---|
256 | #:scale-float |
---|
257 | #:float |
---|
258 | #:floatp |
---|
259 | #:floor |
---|
260 | #:ffloor |
---|
261 | #:ceiling |
---|
262 | #:fceiling |
---|
263 | #:truncate |
---|
264 | #:ftruncate |
---|
265 | #:round |
---|
266 | #:fround |
---|
267 | #:rem |
---|
268 | #:mod |
---|
269 | #:realpart |
---|
270 | #:imagpart |
---|
271 | #:conjugate |
---|
272 | #:float-sign |
---|
273 | #:qd-format-exp |
---|
274 | #:max |
---|
275 | #:min |
---|
276 | #:cis |
---|
277 | #:phase |
---|
278 | #:signum |
---|
279 | #:coerce |
---|
280 | #:random |
---|
281 | #:realp |
---|
282 | #:complexp |
---|
283 | #:numberp |
---|
284 | #:incf |
---|
285 | #:decf |
---|
286 | #:float-digits |
---|
287 | #:rational |
---|
288 | #:rationalize) |
---|
289 | ;; Export Oct-specific functions |
---|
290 | (:export #:make-qd |
---|
291 | #:jacobi-sn |
---|
292 | #:jacobi-cn |
---|
293 | #:jacobi-dn |
---|
294 | #:elliptic-k |
---|
295 | #:elliptic-f |
---|
296 | #:elliptic-e |
---|
297 | #:elliptic-ec |
---|
298 | #:carlson-rd |
---|
299 | #:carlson-rf |
---|
300 | #:carlson-rj |
---|
301 | #:elliptic-theta-1 |
---|
302 | #:elliptic-theta-2 |
---|
303 | #:elliptic-theta-3 |
---|
304 | #:elliptic-theta-4 |
---|
305 | #:elliptic-theta) |
---|
306 | ;; Constants |
---|
307 | (:export #:+pi+ |
---|
308 | #:+pi/2+ |
---|
309 | #:+pi/4+ |
---|
310 | #:+2pi+ |
---|
311 | #:+log2+) |
---|
312 | ;; CMUCL supports infinities. |
---|
313 | #+cmu |
---|
314 | (:export #:+quad-double-float-positive-infinity+ |
---|
315 | #:+quad-double-float-negative-infinity+)) |
---|