GNU Radio 3.7.1 C++ API
volk_complex.h
Go to the documentation of this file.
00001 #ifndef INCLUDE_VOLK_COMPLEX_H
00002 #define INCLUDE_VOLK_COMPLEX_H
00003 
00004 /*!
00005  * \brief Provide typedefs and operators for all complex types in C and C++.
00006  *
00007  * The typedefs encompass all signed integer and floating point types.
00008  * Each operator function is intended to work across all data types.
00009  * Under C++, these operators are defined as inline templates.
00010  * Under C, these operators are defined as preprocessor macros.
00011  * The use of macros makes the operators agnostic to the type.
00012  *
00013  * The following operator functions are defined:
00014  * - lv_cmake - make a complex type from components
00015  * - lv_creal - get the real part of the complex number
00016  * - lv_cimag - get the imaginary part of the complex number
00017  * - lv_conj - take the conjugate of the complex number
00018  */
00019 
00020 #ifdef __cplusplus
00021 
00022 #include <complex>
00023 #include <stdint.h>
00024 
00025 typedef std::complex<int8_t>  lv_8sc_t;
00026 typedef std::complex<int16_t> lv_16sc_t;
00027 typedef std::complex<int32_t> lv_32sc_t;
00028 typedef std::complex<int64_t> lv_64sc_t;
00029 typedef std::complex<float>   lv_32fc_t;
00030 typedef std::complex<double>  lv_64fc_t;
00031 
00032 template <typename T> inline std::complex<T> lv_cmake(const T &r, const T &i){
00033     return std::complex<T>(r, i);
00034 }
00035 
00036 template <typename T> inline typename T::value_type lv_creal(const T &x){
00037     return x.real();
00038 }
00039 
00040 template <typename T> inline typename T::value_type lv_cimag(const T &x){
00041     return x.imag();
00042 }
00043 
00044 template <typename T> inline T lv_conj(const T &x){
00045     return std::conj(x);
00046 }
00047 
00048 #else /* __cplusplus */
00049 
00050 #include <complex.h>
00051 
00052 typedef char complex         lv_8sc_t;
00053 typedef short complex        lv_16sc_t;
00054 typedef long complex         lv_32sc_t;
00055 typedef long long complex    lv_64sc_t;
00056 typedef float complex        lv_32fc_t;
00057 typedef double complex       lv_64fc_t;
00058 
00059 #define lv_cmake(r, i) ((r) + _Complex_I*(i))
00060 
00061 // When GNUC is available, use the complex extensions.
00062 // The extensions always return the correct value type.
00063 // http://gcc.gnu.org/onlinedocs/gcc/Complex.html
00064 #ifdef __GNUC__
00065 
00066 #define lv_creal(x) (__real__(x))
00067 
00068 #define lv_cimag(x) (__imag__(x))
00069 
00070 #define lv_conj(x) (~(x))
00071 
00072 // When not available, use the c99 complex function family,
00073 // which always returns double regardless of the input type.
00074 #else /* __GNUC__ */
00075 
00076 #define lv_creal(x) (creal(x))
00077 
00078 #define lv_cimag(x) (cimag(x))
00079 
00080 #define lv_conj(x) (conj(x))
00081 
00082 #endif /* __GNUC__ */
00083 
00084 #endif /* __cplusplus */
00085 
00086 #endif /* INCLUDE_VOLK_COMPLEX_H */