-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcomplex.hpp
More file actions
198 lines (152 loc) · 3.92 KB
/
Copy pathcomplex.hpp
File metadata and controls
198 lines (152 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Copyright 2018 by Martin Moene
//
// https://github.com/martinmoene/kalman-estimator
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef STD_COMPLEX_INCLUDED
#define STD_COMPLEX_INCLUDED
#if !( defined( __AVR ) && __AVR )
#include <complex>
namespace std20 {
using std::complex;
using std::polar;
} // namespace std20
#else // __AVR
namespace std20 {
template< typename T >
class complex
{
public:
using value_type = T;
constexpr complex( T const & re = T(), T const & im = T() )
: re_( re )
, im_( im )
{}
constexpr complex( complex const & other ) = default;
template< class X >
constexpr complex( complex<X> const & other)
: re_( other.real() )
, im_( other.imag() )
{}
constexpr complex & operator=( T const & x )
{
re_ = x;
im_ = T();
}
constexpr complex & operator=( complex const & cx )
{
re_ = cx.real();
im_ = cx.imag();
}
template<class X>
constexpr complex & operator=( complex<X> const & cx)
{
re_ = cx.real();
im_ = cx.imag();
}
constexpr T real() const
{
return re_;
}
constexpr T imag() const
{
return im_;
}
constexpr void real( T value )
{
re_ = value;
}
constexpr void imag( T value )
{
im_ = value;
}
constexpr complex & operator+=( T const & other );
constexpr complex & operator-=( T const & other );
constexpr complex & operator*=( T const & other );
constexpr complex & operator/=( T const & other );
template<class X>
constexpr complex& operator+=( complex<X> const & other);
template<class X>
constexpr complex& operator-=( complex<X> const & other);
template<class X>
constexpr complex& operator*=( complex<X> const & other);
template<class X>
constexpr complex& operator/=( complex<X> const & other);
private:
value_type re_;
value_type im_;
};
// unary:
template< class T >
constexpr complex<T> operator+( T const & val );
template< class T >
constexpr complex<T> operator-( complex<T> const & val );
// binary:
template< class T >
constexpr complex<T> operator+( complex<T> const & lhs, T const & rhs)
{
return complex(lhs) += rhs;
}
template< class T >
constexpr complex<T> operator-( complex<T> const & lhs, T const & rhs)
{
return complex(lhs) -= rhs;
}
template< class T >
constexpr complex<T> operator*( complex<T> const & lhs, T const & rhs)
{
return complex(lhs) *= rhs;
}
template< class T >
constexpr complex<T> operator/( complex<T> const & lhs, T const & rhs)
{
return complex(lhs) /= rhs;
}
template< class T >
constexpr complex<T> operator+( T const & lhs, complex<T> const & rhs )
{
return complex(lhs) += rhs;
}
template< class T >
constexpr complex<T> operator-( T const & lhs, complex<T> const & rhs )
{
return complex(lhs) -= rhs;
}
template< class T >
constexpr complex<T> operator*( T const & lhs, complex<T> const & rhs )
{
return complex(lhs) *= rhs;
}
template< class T >
constexpr complex<T> operator/( T const & lhs, complex<T> const & rhs )
{
return complex(lhs) /= rhs;
}
template< class T >
constexpr complex<T> operator+( complex<T> const & lhs, complex<T> const & rhs)
{
return complex(lhs) += rhs;
}
template< class T >
constexpr complex<T> operator-( complex<T> const & lhs, complex<T> const & rhs)
{
return complex(lhs) -= rhs;
}
template< class T >
constexpr complex<T> operator*( complex<T> const & lhs, complex<T> const & rhs)
{
return complex(lhs) *= rhs;
}
template< class T >
constexpr complex<T> operator/( complex<T> const & lhs, complex<T> const & rhs)
{
return complex(lhs) /= rhs;
}
template< class T >
T abs( complex<T> const & z );
template< class T >
complex<T> sqrt( complex<T> const & z );
} // naespace std20
#endif // __AVR
#endif // STD_UTILITY_INCLUDED