vnl_complex_traits.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_complex_traits.h
2 #ifndef vnl_complex_traits_h_
3 #define vnl_complex_traits_h_
4 //:
5 // \file
6 // \brief To allow templated algorithms to determine appropriate actions of conjugation, complexification etc.
7 // \author fsm, Oxford RRG, 26 Mar 1999
8 //
9 // \verbatim
10 // Modifications
11 // LSB (Manchester) 26/3/01 Documentation tidied
12 // \endverbatim
13 //-----------------------------------------------------------------------------
14 
15 #include <complex>
16 #ifdef _MSC_VER
17 # include <vcl_msvc_warnings.h>
18 #endif
19 #include "vnl/vnl_export.h"
20 
21 template <class T> // the primary template is empty, by design.
22 struct vnl_complex_traits;
23 
24 #define VCL_DEFINE_SPECIALIZATION_MACRO(T) \
25 template <> struct VNL_EXPORT vnl_complex_traits<T > \
26 { \
27  enum { isreal = true }; \
28  static T conjugate(T x) { return x; } \
29  static std::complex<T> complexify(T x) { return std::complex<T >(x, (T)0); } \
30 }
31 #define VCL_DEFINE_SPECIALIZATION_MACRO_SIGNED_UNSIGNED(T) \
32 VCL_DEFINE_SPECIALIZATION_MACRO(signed T); \
33 VCL_DEFINE_SPECIALIZATION_MACRO(unsigned T)
38 //long long - target type will have width of at least 64 bits. (since C++11)
40 
41 //3.9.1 Fundamental types [basic.fundamental]
42 //Plain char, signed char, and unsigned char are three distinct types
43 // We must explicitly instantiate the char type without signed/unsigned prefix
45 #undef VCL_DEFINE_SPECIALIZATION_MACRO_SIGNED_UNSIGNED
46 #undef VCL_DEFINE_SPECIALIZATION_MACRO
47 
48 
49 template <> struct VNL_EXPORT vnl_complex_traits<float>
50 {
51  enum { isreal = true };
52  static float conjugate(float x) { return x; }
53  static std::complex<float> complexify(float x) { return {x, 0.0f}; }
54 };
55 
56 template <> struct VNL_EXPORT vnl_complex_traits<double>
57 {
58  enum { isreal = true };
59  static double conjugate(double x) { return x; }
60  static std::complex<double> complexify(double x) { return {x, 0.0}; }
61 };
62 
63 template <> struct VNL_EXPORT vnl_complex_traits<long double>
64 {
65  enum { isreal = true };
66  static long double conjugate(long double x) { return x; }
67  static std::complex<long double> complexify(long double x) { return {x, 0.0}; }
68 };
69 
70 template <> struct VNL_EXPORT vnl_complex_traits<std::complex<float> >
71 {
72  enum { isreal = false };
73  static std::complex<float> conjugate(std::complex<float> x) { return std::conj(x); }
74  static std::complex<float> complexify(float x) { return x; }
75 };
76 
77 template <> struct VNL_EXPORT vnl_complex_traits<std::complex<double> >
78 {
79  enum { isreal = false };
80  static std::complex<double> conjugate(std::complex<double> x) { return std::conj(x); }
81  static std::complex<double> complexify(double x) { return x; }
82 };
83 
84 template <> struct VNL_EXPORT vnl_complex_traits<std::complex<long double> >
85 {
86  enum { isreal = false };
87  static std::complex<long double> conjugate(std::complex<long double> x) { return std::conj(x); }
88  static std::complex<long double> complexify(long double x) { return x; }
89 };
90 
91 #include <vnl/vnl_bignum.h>
92 
93 template <> struct VNL_EXPORT vnl_complex_traits<vnl_bignum>
94 {
95  enum { isreal = true };
96  static vnl_bignum conjugate(vnl_bignum x) { return x; }
97  static std::complex<vnl_bignum> complexify(vnl_bignum x) { return std::complex<vnl_bignum>(x,vnl_bignum(0L)); }
98 };
99 
100 template <> struct VNL_EXPORT vnl_complex_traits<std::complex<vnl_bignum> >
101 {
102  enum { isreal = false };
103  static std::complex<vnl_bignum> conjugate(std::complex<vnl_bignum> x) { return std::complex<vnl_bignum>(x.real(),-x.imag()); }
104  static std::complex<vnl_bignum> complexify(std::complex<vnl_bignum> x) { return x; }
105 };
106 
107 #include <vnl/vnl_rational.h>
109 template <> struct VNL_EXPORT vnl_complex_traits<vnl_rational>
110 {
111  enum { isreal = true };
112  static vnl_rational conjugate(vnl_rational x) { return x; }
113  static std::complex<vnl_rational> complexify(vnl_rational x) { return std::complex<vnl_rational>(x, vnl_rational(0,1)); }
114 };
116 template <> struct VNL_EXPORT vnl_complex_traits<std::complex<vnl_rational> >
117 {
118  enum { isreal = false };
119  static std::complex<vnl_rational> conjugate(std::complex<vnl_rational> x) {return std::complex<vnl_rational>(x.real(),-x.imag());}
120  static std::complex<vnl_rational> complexify(std::complex<vnl_rational> x) { return x; }
121 };
122 
123 #endif // vnl_complex_traits_h_
#define VCL_DEFINE_SPECIALIZATION_MACRO_SIGNED_UNSIGNED(T)
Infinite precision integers.
Definition: vnl_bignum.h:143
Infinite precision integers.
#define VCL_DEFINE_SPECIALIZATION_MACRO(T)
High-precision rational numbers.
High-precision rational numbers.
Definition: vnl_rational.h:73