sisi4s
Loading...
Searching...
No Matches
Complex.hpp
Go to the documentation of this file.
1#ifndef COMPLEX_DEFINED
2#define COMPLEX_DEFINED
3
4#include <math/Float.hpp>
5#include <complex>
6
7namespace sisi4s {
8// use standard library complex number support
9template <typename Real>
10using Complex = std::complex<Real>;
11
12// define explicit size complex types
15
16// define complex field over machine supported reals as default complex type
18
19template <typename Real>
20inline Real absSqr(const Real x) {
21 return x * x;
22}
23
24template <typename Real>
25inline Real absSqr(const Complex<Real> z) {
26 return absSqr(z.real()) + absSqr(z.imag());
27}
28
29// type info allowing inference of
30// extended type from given optinoally complex type. e.g.:
31// ComplexTraits<complex>::ExtendedType = real
32// ComplexTraits<real>::ExtendedType = real
33// ComplexTraits<Complex<int>>::ExtendedType = int
34template <typename T>
36public:
37 typedef T ExtendedType;
38};
39
40template <typename T>
42public:
43 typedef T ExtendedType;
44};
45
46// numeric conversions
47template <typename Target, typename Source>
49
50template <typename Target, typename Real>
51class Conversion<Target, Complex<Real>> {
52public:
53 static Target from(const Complex<Real> x) { return Target(x); }
54};
55
56template <typename Real>
57class Conversion<Real, Complex<Real>> {
58public:
59 static Real from(const Complex<Real> x) { return std::real(x); }
60};
61
62} // namespace sisi4s
63
64#endif
T ExtendedType
Definition Complex.hpp:43
Definition Complex.hpp:35
T ExtendedType
Definition Complex.hpp:37
static Real from(const Complex< Real > x)
Definition Complex.hpp:59
static Target from(const Complex< Real > x)
Definition Complex.hpp:53
Definition Complex.hpp:48
Definition Algorithm.hpp:10
Complex< Float64 > Complex64
Definition Complex.hpp:14
Complex< Float32 > Complex32
Definition Complex.hpp:13
std::complex< Real > Complex
Definition Complex.hpp:10
Real absSqr(const Real x)
Definition Complex.hpp:20
Complex< real > complex
Definition Complex.hpp:17