complex-types.lisp 1.43 KB
Newer Older
1
2
;; Complex number types
;; Liam Healy 2009-01-13 21:24:05EST complex-types.lisp
Liam M. Healy's avatar
Liam M. Healy committed
3
;; Time-stamp: <2009-11-16 12:35:49EST complex-types.lisp>
4
5
6
7
8
9
10

(in-package :gsl)

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

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

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

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

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

27
#+long-double
28
(cffi:defcstruct complex-long-double-c
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  (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))

49
50
(defun component-type (eltype)
  (cl-cffi (component-float-type eltype)))