LAL  7.1.7.1-56c71ae
LALAtomicDatatypes.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 /* ---------- SEE LALDatatypes.dox for doxygen documentation ---------- */
21 
22 #ifndef _LALATOMICDATATYPES_H
23 #define _LALATOMICDATATYPES_H
24 
25 #include <stdint.h>
26 #include <lal/LALConfig.h>
27 #include <lal/LALStddef.h>
28 
29 #if defined(__cplusplus)
30 extern "C" {
31 #elif 0
32 } /* so that editors will match preceding brace */
33 #endif
34 
35 /** \addtogroup LALDatatypes */ /** @{ */
36 
37 typedef char CHAR; /**< One-byte signed integer, see \ref LALDatatypes for more details */
38 typedef unsigned char UCHAR; /**< One-byte unsigned integer, see \ref LALDatatypes for more details */
39 typedef unsigned char BOOLEAN; /**< Boolean logical type, see \ref LALDatatypes for more details */
40 
41 /* If INT8 etc. are already defined, undefine them */
42 #undef CHAR
43 #undef UCHAR
44 #undef INT2
45 #undef INT4
46 #undef INT8
47 #undef UINT2
48 #undef UINT4
49 #undef UINT8
50 #undef REAL4
51 #undef REAL8
52 #undef COMPLEX8
53 #undef COMPLEX16
54 
55 /* Integer types */
56 typedef int16_t INT2; /**< Two-byte signed integer */
57 typedef int32_t INT4; /**< Four-byte signed integer. */
58 typedef uint16_t UINT2; /**< Two-byte unsigned integer. */
59 typedef uint32_t UINT4; /**< Four-byte unsigned integer. */
60 #ifndef _NO_INT8_BY_LAL
61 typedef int64_t INT8; /**< Eight-byte signed integer; on some platforms this is equivalent to <tt>long int</tt> instead. */
62 typedef uint64_t UINT8; /**< Eight-byte unsigned integer; on some platforms this is equivalent to <tt>unsigned long int</tt> instead. */
63 #endif
64 
65 /** MACRO to initialize arbitrary variable 'x' to zero */
66 #define XLAL_INIT_MEM(x) memset(&(x), 0, sizeof((x)))
67 /** C99 MACRO to declare and zero-initialize a variable, use as "type XLAL_INIT_DECL(var);".
68  To declare and zero-initialize an array variable, use as "type XLAL_INIT_DECL(var, [n]);" */
69 #define XLAL_INIT_DECL(var, ...) var __VA_ARGS__; XLAL_INIT_MEM(var)
70 
71 /** MACRO which gives the number of elements in a fixed-size array */
72 #define XLAL_NUM_ELEM(x) ( sizeof((x)) / sizeof((x)[0]) )
73 /** MACRO to access the last element in a fixed-size array */
74 #define XLAL_LAST_ELEM(x) (x)[ XLAL_NUM_ELEM(x) - 1 ]
75 
76 /* Macros for integer constants */
77 /**
78  * \def LAL_INT8_C(v) (v ## LL)
79  * \brief Macro for use in defining \a v as an INT8 constant.
80  *
81  * This macro affixes the appropriate qualifier to form an INT8 constant.
82  * For example:
83  * \code
84  * const INT8 jan_1_2000_gps_nanosec = LAL_INT8_C(63072001300000000)
85  * \endcode
86  */
87 #define LAL_INT8_C(c) INT64_C(c)
88 
89 /**
90  * \def LAL_UINT8_C(v) (v ## ULL)
91  * \brief Macro for use in defining \a v as an UINT8 constant.
92  *
93  * This macro affixes the appropriate qualifier to form an UINT8 constant.
94  * For example:
95  * \code
96  * const UINT8 jan_1_2000_gps_nanosec = LAL_UINT8_C(63072001300000000)
97  * \endcode
98  */
99 #define LAL_UINT8_C(c) UINT64_C(c)
100 
101 /* Real types */
102 typedef float REAL4; /**< Single precision real floating-point number (4 bytes). */
103 typedef double REAL8; /**< Double precision real floating-point number (8 bytes). */
104 
105 /* Complex types */
106 #ifndef SWIG /* exclude from SWIG interface */
107 
108 /* Use C99 complex numbers where available: C99, gcc with non-ANSI extensions */
109 #if !defined(__cplusplus)
110 # if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
111 # define _LAL_C99_COMPLEX_NUMBERS_
112 # endif
113 #endif
114 
115 #ifdef _LAL_C99_COMPLEX_NUMBERS_
116 
117 #include <complex.h>
118 
119 typedef float complex COMPLEX8; /**< Single-precision floating-point complex number (8 bytes total) */
120 typedef double complex COMPLEX16; /**< Double-precision floating-point complex number (16 bytes total) */
121 
122 #define crectf(re, im) (((REAL4)(re)) + _Complex_I*((REAL4)(im))) /**< Construct a COMPLEX8 from real and imaginary parts */
123 #define crect(re, im) (((REAL8)(re)) + _Complex_I*((REAL8)(im))) /**< Construct a COMPLEX16 from real and imaginary parts */
124 #define cpolarf(r, th) (((REAL4)(r)) * cexpf(crectf(0, th))) /**< Construct a COMPLEX8 from polar modulus and argument */
125 #define cpolar(r, th) (((REAL8)(r)) * cexp(crect(0, th))) /**< Construct a COMPLEX16 from polar modulus and argument */
126 
127 #else /* !_LAL_C99_COMPLEX_NUMBERS_ */
128 /** \cond DONT_DOXYGEN */
129 
130 /****************************************************************************/
131 /* Fall back to GSL complex number types if C99 complex numbers are not */
132 /* available. GSL complex numbers are implemented as a struct containing */
133 /* an array of 2 elements of the corresponding real type. The C99 standard */
134 /* should guarantee that GSL complex numbers are binary-compatible with C99 */
135 /* complex numbers; 6.2.5 point 13 of the standard states that C99 complex */
136 /* numbers are equivalent to an array of 2 elements of the corresponding */
137 /* real type, and 6.7.2.1 point 13 states that padding is never added to */
138 /* the beginning of a struct. */
139 /****************************************************************************/
140 
141 #include <math.h>
142 #include <gsl/gsl_complex.h>
143 
144 typedef gsl_complex_float COMPLEX8;
145 typedef gsl_complex COMPLEX16;
146 
147 static _LAL_INLINE_ COMPLEX8 crectf(const REAL4 re, const REAL4 im);
148 static _LAL_INLINE_ COMPLEX8 crectf(const REAL4 re, const REAL4 im) {
149  COMPLEX8 z; GSL_SET_COMPLEX(&z, re, im); return z;
150 }
151 static _LAL_INLINE_ COMPLEX16 crect(const REAL8 re, const REAL8 im);
152 static _LAL_INLINE_ COMPLEX16 crect(const REAL8 re, const REAL8 im) {
153  COMPLEX16 z; GSL_SET_COMPLEX(&z, re, im); return z;
154 }
155 static _LAL_INLINE_ COMPLEX8 cpolarf(const REAL4 r, const REAL4 th);
156 static _LAL_INLINE_ COMPLEX8 cpolarf(const REAL4 r, const REAL4 th) {
157  COMPLEX8 z; GSL_SET_COMPLEX(&z, r*cos(th), r*sin(th)); return z;
158 }
159 static _LAL_INLINE_ COMPLEX16 cpolar(const REAL8 r, const REAL8 th);
160 static _LAL_INLINE_ COMPLEX16 cpolar(const REAL8 r, const REAL8 th) {
161  COMPLEX16 z; GSL_SET_COMPLEX(&z, r*cos(th), r*sin(th)); return z;
162 }
163 
164 #define crealf(z) GSL_REAL(z)
165 #define cimagf(z) GSL_IMAG(z)
166 #define creal(z) GSL_REAL(z)
167 #define cimag(z) GSL_IMAG(z)
168 
169 /** \endcond */
170 #endif /* _LAL_C99_COMPLEX_NUMBERS_ */
171 
172 #endif /* SWIG */
173 
174 /** @} */
175 
176 #if 0
177 { /* so that editors will match succeeding brace */
178 #elif defined(__cplusplus)
179 }
180 #endif
181 
182 #endif /* _LALATOMICDATATYPES_H */
#define cpolar(r, th)
Construct a COMPLEX16 from polar modulus and argument.
#define crectf(re, im)
Construct a COMPLEX8 from real and imaginary parts.
int16_t INT2
Two-byte signed integer.
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)
unsigned char UCHAR
One-byte unsigned integer, see Headers LAL(Atomic)Datatypes.h for more details.
float REAL4
Single precision real floating-point number (4 bytes).
#define _LAL_INLINE_
Definition: LALStddef.h:27
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead...
double REAL8
Double precision real floating-point number (8 bytes).
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
uint16_t UINT2
Two-byte unsigned integer.
#define cpolarf(r, th)
Construct a COMPLEX8 from polar modulus and argument.
double complex COMPLEX16
Double-precision floating-point complex number (16 bytes total)
static const INT4 r
Definition: Random.c:82
#define crect(re, im)
Construct a COMPLEX16 from real and imaginary parts.
int32_t INT4
Four-byte signed integer.
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.