1 #ifndef __SDR_OPERATORS_HH__
2 #define __SDR_OPERATORS_HH__
10 inline int16_t conj(int16_t value) {
return value; }
11 inline int16_t real(int16_t value) {
return value; }
12 inline int16_t imag(int16_t value) {
return 0; }
16 inline std::complex<double> operator*(
const double &a,
const std::complex<float> &b) {
17 return std::complex<double>(a*b.real(), a*b.imag());
20 inline std::complex<double> operator*(
const double &a,
const std::complex<uint16_t> &b) {
21 return std::complex<double>(a*b.real(), a*b.imag());
24 inline std::complex<double> operator*(
const double &a,
const std::complex<int16_t> &b) {
25 return std::complex<double>(a*b.real(), a*b.imag());
28 inline std::complex<double> operator*(
const double &a,
const std::complex<uint8_t> &b) {
29 return std::complex<double>(a*b.real(), a*b.imag());
32 inline std::complex<double> operator*(
const double &a,
const std::complex<int8_t> &b) {
33 return std::complex<double>(a*b.real(), a*b.imag());
36 inline std::complex<float> operator* (
const std::complex<float> &a,
const std::complex<int16_t> &b) {
37 return a*std::complex<float>(std::real(b), std::imag(b));
40 inline std::complex<double> operator* (
const std::complex<double> &a,
const std::complex<int16_t> &b) {
41 return a*std::complex<double>(std::real(b), std::imag(b));
44 inline std::complex<int32_t> operator<< (const std::complex<int32_t> &a,
int b) {
45 return std::complex<int32_t>(std::real(a)<<b, std::imag(a)<<b);
48 inline std::complex<int32_t> operator>> (
const std::complex<int32_t> &a,
int b) {
49 return std::complex<int32_t>(std::real(a)>>b, std::imag(a)>>b);
55 template <
class iScalar,
class oScalar>
56 inline oScalar cast(
const iScalar &a) {
return oScalar(a); }
59 inline std::complex<double> cast<int8_t, std::complex<double> >(
const int8_t &a) {
60 return std::complex<double>(std::real(a), std::imag(a));
64 inline std::complex<double> cast<std::complex<int8_t>, std::complex<double> >(
const std::complex<int8_t> &a) {
65 return std::complex<double>(std::real(a), std::imag(a));
69 inline std::complex<double> cast<int16_t, std::complex<double> >(
const int16_t &a) {
70 return std::complex<double>(std::real(a), std::imag(a));
74 inline std::complex<double> cast<std::complex<int16_t>, std::complex<double> >(
const std::complex<int16_t> &a) {
75 return std::complex<double>(std::real(a), std::imag(a));
80 inline uint8_t mul2(uint8_t a,
int n) {
81 if (n < 0) {
return a >> -n; }
82 else {
return a << n; }
86 inline uint8_t div2(uint8_t a,
int n) {
87 if (n < 0) {
return a << -n; }
88 else {
return a >> n; }
92 inline std::complex<uint8_t> mul2(
const std::complex<uint8_t> &a,
int n) {
94 return std::complex<uint8_t>(std::real(a)>>(-n), std::imag(a)>>(-n));
96 return std::complex<uint8_t>(std::real(a)<<(n), std::imag(a)<<(n));
101 inline std::complex<uint8_t> div2(
const std::complex<uint8_t> &a,
int n) {
103 return std::complex<uint8_t>(std::real(a)<<(-n), std::imag(a)<<(-n));
105 return std::complex<uint8_t>(std::real(a)>>(n), std::imag(a)>>(n));
110 inline int8_t mul2(int8_t a,
int n) {
111 if (n < 0) {
return a >> -n; }
112 else {
return a << n; }
116 inline std::complex<int8_t> mul2(
const std::complex<int8_t> &a,
int n) {
118 return std::complex<int8_t>(std::real(a)>>(-n), std::imag(a)>>(-n));
120 return std::complex<int8_t>(std::real(a)>>(-n), std::imag(a)>>(-n));
125 inline uint16_t mul2(uint16_t a,
int n) {
126 if (n < 0) {
return a >> -n; }
127 else {
return a << n; }
131 inline std::complex<uint16_t> mul2(
const std::complex<uint16_t> &a,
int n) {
133 return std::complex<uint16_t>(std::real(a)>>(-n), std::imag(a)>>(-n));
135 return std::complex<uint16_t>(std::real(a)>>(-n), std::imag(a)>>(-n));
140 inline int16_t mul2(int16_t a,
int n) {
141 if (n < 0) {
return a >> -n; }
142 else {
return a << n; }
146 inline std::complex<int16_t> mul2(
const std::complex<int16_t> &a,
int n) {
148 return std::complex<int16_t>(std::real(a)>>(-n), std::imag(a)>>(-n));
150 return std::complex<int16_t>(std::real(a)>>(-n), std::imag(a)>>(-n));
155 inline float mul2(
float a,
int n) {
156 if (n < 0) {
return a/(1<<(-n)); }
157 else {
return a*(1<<n); }
161 inline std::complex<float> mul2(
const std::complex<float> &a,
int n) {
162 if (n < 0) {
return a/float(1<<(-n)); }
163 else {
return a*float(1<<n); }
167 inline std::complex<double> mul2(
const std::complex<double> &a,
int n) {
168 if (n < 0) {
return a/double(1<<(-n)); }
169 else {
return a*double(1<<n); }
174 #endif // OPERATORS_HH
Definition: autocast.hh:8
Definition: operators.hh:9