-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path%complex.lisp
More file actions
184 lines (128 loc) · 6.93 KB
/
Copy path%complex.lisp
File metadata and controls
184 lines (128 loc) · 6.93 KB
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
175
176
177
178
179
180
181
182
183
184
;;; -*- Mode: LISP; Base: 10; Syntax: ANSI-Common-Lisp; Package: %LIBM -*-
;;; Copyright (c) 2020 by Symbolics Pte. Ltd. All rights reserved.
(cl:in-package #:%libm-complex)
;;; Complex numbers require libffi. This is easily available on
;;; FreeBSD or Mac, but less so on MS Windows. That's why this is a
;;; separate system and package, so that it can be loaded
;;; independently. See below for the Python guys view on libffi:
;;; https://cffi.readthedocs.io/en/latest/installation.html#platform-specific-instructions
;;; Double complex definitions
(cffi:defcstruct (complex-double-c :class complex-double-type)
(dat :double :count 2))
(cl:defmethod cffi:translate-into-foreign-memory ((value cl:complex) (type complex-double-type) p)
(cffi:with-foreign-slots ((dat) p (:struct complex-double-c))
(cl:setf (cffi:mem-aref dat :double 0) (cl:realpart value)
(cffi:mem-aref dat :double 1) (cl:imagpart value))))
(cl:defmethod cffi:translate-from-foreign (p (type complex-double-type))
(cffi:with-foreign-slots ((dat) p (:struct complex-double-c))
(cl:complex (cffi:mem-aref dat :double 0)
(cffi:mem-aref dat :double 1))))
;;; Float complex definitions
(cffi:defcstruct (complex-float-c :class complex-float-type)
(dat :float :count 2))
(cl:defmethod cffi:translate-into-foreign-memory ((value cl:complex) (type complex-float-type) p)
(cffi:with-foreign-slots ((dat) p (:struct complex-float-c))
(cl:setf (cffi:mem-aref dat :float 0) (cl:realpart value)
(cffi:mem-aref dat :float 1) (cl:imagpart value))))
(cl:defmethod cffi:translate-from-foreign (p (type complex-float-type))
(cffi:with-foreign-slots ((dat) p (:struct complex-float-c))
(cl:complex (cffi:mem-aref dat :float 0)
(cffi:mem-aref dat :float 1))))
;;;
;;; Double versions of C99 functions
;;;
;; double complex cacos(double complex);
(cffi:defcfun "cacos" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex casin(double complex);
(cffi:defcfun "casin" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex catan(double complex);
(cffi:defcfun "catan" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex ccos(double complex);
(cffi:defcfun "ccos" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex csin(double complex);
(cffi:defcfun "csin" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex ctan(double complex);
(cffi:defcfun "ctan" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex cacosh(double complex);
(cffi:defcfun "cacosh" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex casinh(double complex);
(cffi:defcfun "casinh" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex catanh(double complex);
(cffi:defcfun "catanh" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex ccosh(double complex);
(cffi:defcfun "ccosh" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex csinh(double complex);
(cffi:defcfun "csinh" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex ctanh(double complex);
(cffi:defcfun "ctanh" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex cexp(double complex);
(cffi:defcfun "cexp" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex clog(double complex);
(cffi:defcfun "clog" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double cabs(double complex);
(cffi:defcfun "cabs" :double (c (:struct complex-double-c)))
;; double complex cpow(double complex, double complex);
(cffi:defcfun "cpow" (:struct complex-double-c)
(c1 (:struct complex-double-c))
(c2 (:struct complex-double-c)))
;; double complex csqrt(double complex);
(cffi:defcfun "csqrt" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double carg(double complex);
(cffi:defcfun "carg" :double (c (:struct complex-double-c)))
;; double cimag(double complex);
(cffi:defcfun "cimag" :double (c (:struct complex-double-c)))
;; double complex conj(double complex);
(cffi:defcfun "conj" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double complex cproj(double complex);
(cffi:defcfun "cproj" (:struct complex-double-c) (c (:struct complex-double-c)))
;; double creal(double complex);
(cffi:defcfun "creal" :double (c (:struct complex-double-c)))
;;;
;;; Float versions of C99 functions
;;;
;; float complex cacosf(float complex);
(cffi:defcfun "cacosf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex casinf(float complex);
(cffi:defcfun "casinf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex catanf(float complex);
(cffi:defcfun "catanf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex ccosf(float complex);
(cffi:defcfun "ccosf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex csinf(float complex);
(cffi:defcfun "csinf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex ctanf(float complex);
(cffi:defcfun "ctanf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex cacoshf(float complex);
(cffi:defcfun "cacoshf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex casinhf(float complex);
(cffi:defcfun "casinhf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex catanhf(float complex);
(cffi:defcfun "catanhf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex ccoshf(float complex);
(cffi:defcfun "ccoshf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex csinhf(float complex);
(cffi:defcfun "csinhf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex ctanhf(float complex);
(cffi:defcfun "ctanhf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex cexpf(float complex);
(cffi:defcfun "cexpf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex clogf(float complex);
(cffi:defcfun "clogf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float cabsf(float complex);
(cffi:defcfun "cabsf" :float (c (:struct complex-float-c)))
;; float complex cpowf(float complex, float complex);
(cffi:defcfun "cpowf" (:struct complex-float-c)
(c1 (:struct complex-float-c))
(c2 (:struct complex-float-c)))
;; float complex csqrtf(float complex);
(cffi:defcfun "csqrtf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float cargf(float complex);
(cffi:defcfun "cargf" :float (c (:struct complex-float-c)))
;; float cimagf(float complex);
(cffi:defcfun "cimagf" :float (c (:struct complex-float-c)))
;; float complex conjf(float complex);
(cffi:defcfun "conjf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float complex cprojf(float complex);
(cffi:defcfun "cprojf" (:struct complex-float-c) (c (:struct complex-float-c)))
;; float crealf(float complex);
(cffi:defcfun "crealf" :float (c (:struct complex-float-c)))