GNU Radio 3.5.3.1 C++ API
volk_complex.h
Go to the documentation of this file.
1
#ifndef INCLUDE_VOLK_COMPLEX_H
2
#define INCLUDE_VOLK_COMPLEX_H
3
4
/*!
5
* \brief Provide typedefs and operators for all complex types in C and C++.
6
*
7
* The typedefs encompass all signed integer and floating point types.
8
* Each operator function is intended to work across all data types.
9
* Under C++, these operators are defined as inline templates.
10
* Under C, these operators are defined as preprocessor macros.
11
* The use of macros makes the operators agnostic to the type.
12
*
13
* The following operator functions are defined:
14
* - lv_cmake - make a complex type from components
15
* - lv_creal - get the real part of the complex number
16
* - lv_cimag - get the imaginary part of the complex number
17
* - lv_conj - take the conjugate of the complex number
18
*/
19
20
#ifdef __cplusplus
21
22
#include <complex>
23
#include <stdint.h>
24
25
typedef
std::complex<int8_t>
lv_8sc_t
;
26
typedef
std::complex<int16_t>
lv_16sc_t
;
27
typedef
std::complex<int32_t>
lv_32sc_t
;
28
typedef
std::complex<int64_t>
lv_64sc_t
;
29
typedef
std::complex<float>
lv_32fc_t
;
30
typedef
std::complex<double>
lv_64fc_t
;
31
32
template
<
typename
T>
inline
std::complex<T>
lv_cmake
(
const
T &r,
const
T &i){
33
return
std::complex<T>(r, i);
34
}
35
36
template
<
typename
T>
inline
typename
T::value_type
lv_creal
(
const
T &x){
37
return
x.real();
38
}
39
40
template
<
typename
T>
inline
typename
T::value_type
lv_cimag
(
const
T &x){
41
return
x.imag();
42
}
43
44
template
<
typename
T>
inline
T
lv_conj
(
const
T &x){
45
return
std::conj(x);
46
}
47
48
#else
/* __cplusplus */
49
50
#include <complex.h>
51
52
typedef
char
complex
lv_8sc_t
;
53
typedef
short
complex
lv_16sc_t
;
54
typedef
long
complex
lv_32sc_t
;
55
typedef
long
long
complex
lv_64sc_t
;
56
typedef
float
complex
lv_32fc_t
;
57
typedef
double
complex
lv_64fc_t
;
58
59
#define lv_cmake(r, i) ((r) + _Complex_I*(i))
60
61
// When GNUC is available, use the complex extensions.
62
// The extensions always return the correct value type.
63
// http://gcc.gnu.org/onlinedocs/gcc/Complex.html
64
#ifdef __GNUC__
65
66
#define lv_creal(x) (__real__(x))
67
68
#define lv_cimag(x) (__imag__(x))
69
70
#define lv_conj(x) (~(x))
71
72
// When not available, use the c99 complex function family,
73
// which always returns double regardless of the input type.
74
#else
/* __GNUC__ */
75
76
#define lv_creal(x) (creal(x))
77
78
#define lv_cimag(x) (cimag(x))
79
80
#define lv_conj(x) (conj(x))
81
82
#endif
/* __GNUC__ */
83
84
#endif
/* __cplusplus */
85
86
#endif
/* INCLUDE_VOLK_COMPLEX_H */
volk
include
volk
volk_complex.h
Generated by
1.8.1.1