1 /* complex/gsl_complex.h
2  *
3  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18  * USA.
19  */
20 
21 #ifndef __GSL_COMPLEX_H__
22 #define __GSL_COMPLEX_H__
23 
24 #undef __BEGIN_DECLS
25 #undef __END_DECLS
26 #ifdef __cplusplus
27 #define __BEGIN_DECLS extern "C" {
28 #define __END_DECLS }
29 #else
30 #define __BEGIN_DECLS /* empty */
31 #define __END_DECLS   /* empty */
32 #endif
33 
34 __BEGIN_DECLS
35 
36 /* two consecutive built-in types as a complex number */
37 typedef double *gsl_complex_packed;
38 typedef float *gsl_complex_packed_float;
39 typedef long double *gsl_complex_packed_long_double;
40 
41 typedef const double *gsl_const_complex_packed;
42 typedef const float *gsl_const_complex_packed_float;
43 typedef const long double *gsl_const_complex_packed_long_double;
44 
45 /* 2N consecutive built-in types as N complex numbers */
46 typedef double *gsl_complex_packed_array;
47 typedef float *gsl_complex_packed_array_float;
48 typedef long double *gsl_complex_packed_array_long_double;
49 
50 typedef const double *gsl_const_complex_packed_array;
51 typedef const float *gsl_const_complex_packed_array_float;
52 typedef const long double *gsl_const_complex_packed_array_long_double;
53 
54 /* Yes... this seems weird. Trust us. The point is just that
55    sometimes you want to make it obvious that something is
56    an output value. The fact that it lacks a 'const' may not
57    be enough of a clue for people in some contexts.
58  */
59 typedef double *gsl_complex_packed_ptr;
60 typedef float *gsl_complex_packed_float_ptr;
61 typedef long double *gsl_complex_packed_long_double_ptr;
62 
63 typedef const double *gsl_const_complex_packed_ptr;
64 typedef const float *gsl_const_complex_packed_float_ptr;
65 typedef const long double *gsl_const_complex_packed_long_double_ptr;
66 
67 typedef struct {
68     long double dat[2];
69 } gsl_complex_long_double;
70 
71 typedef struct {
72     double dat[2];
73 } gsl_complex;
74 
75 typedef struct {
76     float dat[2];
77 } gsl_complex_float;
78 
79 #define GSL_REAL(z) ((z).dat[0])
80 #define GSL_IMAG(z) ((z).dat[1])
81 #define GSL_COMPLEX_P(zp) ((zp)->dat)
82 #define GSL_COMPLEX_P_REAL(zp) ((zp)->dat[0])
83 #define GSL_COMPLEX_P_IMAG(zp) ((zp)->dat[1])
84 #define GSL_COMPLEX_EQ(z1, z2)                                                 \
85     (((z1).dat[0] == (z2).dat[0]) && ((z1).dat[1] == (z2).dat[1]))
86 
87 #define GSL_SET_COMPLEX(zp, x, y)                                              \
88     do {                                                                       \
89         (zp)->dat[0] = (x);                                                    \
90         (zp)->dat[1] = (y);                                                    \
91     } while (0)
92 #define GSL_SET_REAL(zp, x)                                                    \
93     do {                                                                       \
94         (zp)->dat[0] = (x);                                                    \
95     } while (0)
96 #define GSL_SET_IMAG(zp, y)                                                    \
97     do {                                                                       \
98         (zp)->dat[1] = (y);                                                    \
99     } while (0)
100 
101 #define GSL_SET_COMPLEX_PACKED(zp, n, x, y)                                    \
102     do {                                                                       \
103         *((zp) + 2 * (n)) = (x);                                               \
104         *((zp) + (2 * (n) + 1)) = (y);                                         \
105     } while (0)
106 
107 __END_DECLS
108 
109 #endif /* __GSL_COMPLEX_H__ */
110