complex-types.lisp 1.51 KB
Newer Older
1
2
;; Complex number types
;; Liam Healy 2009-01-13 21:24:05EST complex-types.lisp
Liam Healy's avatar
Liam Healy committed
3
;; Time-stamp: <2009-12-06 22:05:59EST complex-types.lisp>
4

Liam Healy's avatar
Liam Healy committed
5
6
7
(in-package :c-array)

(export '(complex-double-c complex-float-c component-float-type component-type))
8
9
10
11
12

;;;;****************************************************************************
;;;; Complex types
;;;;****************************************************************************

Liam Healy's avatar
Liam Healy committed
13
#+fsbv
14
15
(fsbv:defcstruct
    (complex-float-c :constructor complex :deconstructor (realpart imagpart))
16
17
  (dat :float :count 2))

Liam Healy's avatar
Liam Healy committed
18
19
20
21
#-fsbv
(cffi:defcstruct complex-float-c (dat :float :count 2))

#+fsbv
22
23
(fsbv:defcstruct
    (complex-double-c :constructor complex :deconstructor (realpart imagpart))
24
25
  (dat :double :count 2))

Liam Healy's avatar
Liam Healy committed
26
27
28
#-fsbv
(cffi:defcstruct complex-double-c (dat :double :count 2))

29
#+long-double
30
(cffi:defcstruct complex-long-double-c
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  (dat :long-double :count 2))

(defun clean-type (type)
  ;; SBCL at least will specify limits on the type, e.g.
  ;; (type-of #C(1.0 2.0))
  ;; (COMPLEX (DOUBLE-FLOAT 1.0 2.0))
  ;; This cleans that up to make
  ;; (clean-type (type-of #C(1.0 2.0)))
  ;; (COMPLEX DOUBLE-FLOAT)
  (if (and (subtypep type 'complex) (listp (second type)))
      (list (first type) (first (second type)))
      type))

(defun component-float-type (eltype)
  "The type of the component of this type (complex)."
  (if (subtypep eltype 'complex)
      ;; complex: use the component type
      (second eltype)
      eltype))

51
52
(defun component-type (eltype)
  (cl-cffi (component-float-type eltype)))
Liam Healy's avatar
Liam Healy committed
53