Pothos  0.4.1-gb758ed46
The Pothos dataflow programming software suite
QFormat.hpp
Go to the documentation of this file.
1 
11 #include <Pothos/Config.hpp>
12 #include <type_traits>
13 #include <complex>
14 #include <cmath>
15 
16 namespace Pothos {
17 namespace Util {
18 
34 template <typename T, typename U>
35 typename std::enable_if<std::is_floating_point<U>::value, T>::type
36 fromQ(const U &in, const int = 0)
37 {
38  return T(in);
39 }
40 
41 template <typename T, typename U>
42 typename std::enable_if<std::is_integral<U>::value, T>::type
43 fromQ(const U &in, const int n = sizeof(U)*4)
44 {
45  return T(in >> n);
46 }
47 
48 template <typename T, typename U>
49 typename std::enable_if<std::is_floating_point<U>::value, T>::type
50 fromQ(const std::complex<U> &in, const int = 0)
51 {
52  return T(in);
53 }
54 
55 template <typename T, typename U>
56 typename std::enable_if<std::is_integral<U>::value, T>::type
57 fromQ(const std::complex<U> &in, const int n = sizeof(U)*4)
58 {
59  auto real = fromQ<typename T::value_type, U>(in.real(), n);
60  auto imag = fromQ<typename T::value_type, U>(in.imag(), n);
61  return T(real, imag);
62 }
63 
81 template <typename T, typename U>
82 typename std::enable_if<std::is_floating_point<T>::value, T>::type
83 floatToQ(const U &in, const int = 0)
84 {
85  return T(in);
86 }
87 
88 template <typename T, typename U>
89 typename std::enable_if<std::is_integral<T>::value, T>::type
90 floatToQ(const U &in, const int n = sizeof(T)*4)
91 {
92  return T(std::ldexp(in, n));
93 }
94 
95 template <typename T, typename U>
96 typename std::enable_if<std::is_floating_point<typename T::value_type>::value, T>::type
97 floatToQ(const std::complex<U> &in, const int = 0)
98 {
99  return T(in);
100 }
101 
102 template <typename T, typename U>
103 typename std::enable_if<std::is_integral<typename T::value_type>::value, T>::type
104 floatToQ(const std::complex<U> &in, const int n = sizeof(typename T::value_type)*4)
105 {
106  auto real = floatToQ<typename T::value_type, U>(in.real(), n);
107  auto imag = floatToQ<typename T::value_type, U>(in.imag(), n);
108  return T(real, imag);
109 }
110 
113 } //namespace Util
114 } //namespace Pothos
std::enable_if< std::is_floating_point< T >::value, T >::type floatToQ(const U &in, const int=0)
Definition: QFormat.hpp:83
std::enable_if< std::is_floating_point< U >::value, T >::type fromQ(const U &in, const int=0)
Definition: QFormat.hpp:36
Definition: Testing.hpp:134