gps_pvt 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +5 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/Gemfile +10 -0
  6. data/README.md +86 -0
  7. data/Rakefile +86 -0
  8. data/bin/console +15 -0
  9. data/bin/setup +8 -0
  10. data/ext/gps_pvt/Coordinate/Coordinate_wrap.cxx +6613 -0
  11. data/ext/gps_pvt/GPS/GPS_wrap.cxx +16019 -0
  12. data/ext/gps_pvt/SylphideMath/SylphideMath_wrap.cxx +21050 -0
  13. data/ext/gps_pvt/extconf.rb +70 -0
  14. data/ext/ninja-scan-light/tool/navigation/EGM.h +2971 -0
  15. data/ext/ninja-scan-light/tool/navigation/GPS.h +2432 -0
  16. data/ext/ninja-scan-light/tool/navigation/GPS_Solver.h +479 -0
  17. data/ext/ninja-scan-light/tool/navigation/GPS_Solver_Base.h +1081 -0
  18. data/ext/ninja-scan-light/tool/navigation/GPS_Solver_MultiFrequency.h +199 -0
  19. data/ext/ninja-scan-light/tool/navigation/GPS_Solver_RAIM.h +210 -0
  20. data/ext/ninja-scan-light/tool/navigation/MagneticField.h +928 -0
  21. data/ext/ninja-scan-light/tool/navigation/NTCM.h +211 -0
  22. data/ext/ninja-scan-light/tool/navigation/RINEX.h +1781 -0
  23. data/ext/ninja-scan-light/tool/navigation/WGS84.h +186 -0
  24. data/ext/ninja-scan-light/tool/navigation/coordinate.h +406 -0
  25. data/ext/ninja-scan-light/tool/param/bit_array.h +145 -0
  26. data/ext/ninja-scan-light/tool/param/complex.h +558 -0
  27. data/ext/ninja-scan-light/tool/param/matrix.h +4049 -0
  28. data/ext/ninja-scan-light/tool/param/matrix_fixed.h +665 -0
  29. data/ext/ninja-scan-light/tool/param/matrix_special.h +562 -0
  30. data/ext/ninja-scan-light/tool/param/quaternion.h +765 -0
  31. data/ext/ninja-scan-light/tool/param/vector3.h +651 -0
  32. data/ext/ninja-scan-light/tool/swig/Coordinate.i +177 -0
  33. data/ext/ninja-scan-light/tool/swig/GPS.i +1102 -0
  34. data/ext/ninja-scan-light/tool/swig/SylphideMath.i +1234 -0
  35. data/ext/ninja-scan-light/tool/swig/extconf.rb +5 -0
  36. data/ext/ninja-scan-light/tool/swig/makefile +53 -0
  37. data/ext/ninja-scan-light/tool/swig/spec/GPS_spec.rb +417 -0
  38. data/ext/ninja-scan-light/tool/swig/spec/SylphideMath_spec.rb +489 -0
  39. data/gps_pvt.gemspec +57 -0
  40. data/lib/gps_pvt/receiver.rb +375 -0
  41. data/lib/gps_pvt/ubx.rb +148 -0
  42. data/lib/gps_pvt/version.rb +5 -0
  43. data/lib/gps_pvt.rb +9 -0
  44. data/sig/gps_pvt.rbs +4 -0
  45. metadata +117 -0
@@ -0,0 +1,145 @@
1
+ /*
2
+ * Copyright (c) 2021, M.Naruoka (fenrir)
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ *
8
+ * - Redistributions of source code must retain the above copyright notice,
9
+ * this list of conditions and the following disclaimer.
10
+ * - Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the documentation
12
+ * and/or other materials provided with the distribution.
13
+ * - Neither the name of the naruoka.org nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software
15
+ * without specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
21
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ *
30
+ */
31
+
32
+ /** @file
33
+ * @brief bit array library as an alternation of std::bitset
34
+ */
35
+
36
+
37
+ #ifndef __BIT_ARRAY_H__
38
+ #define __BIT_ARRAY_H__
39
+
40
+ #include <climits>
41
+ #include <cstring>
42
+ #include <cstdlib>
43
+
44
+ #include <vector>
45
+
46
+ template <int denom, int pow2 = 1, int log2 = 0, int rem2 = denom % pow2>
47
+ struct const_div_t : public std::div_t {
48
+ const_div_t(const int &num) : std::div_t(std::div(num, denom)) {}
49
+ };
50
+ template <int denom, int pow2, int log2>
51
+ struct const_div_t<denom, pow2, log2, 0> : public const_div_t<denom, (pow2 << 1), log2 + 1> {
52
+ const_div_t(const int &num) : const_div_t<denom, (pow2 << 1), log2 + 1>(num) {}
53
+ };
54
+ template <int denom, int log2>
55
+ struct const_div_t<denom, denom, log2, 0> {
56
+ int quot, rem;
57
+ const_div_t(const int &num) : quot(num >> log2), rem(num & (denom - 1)) {}
58
+ };
59
+
60
+ template <int MAX_SIZE, class ContainerT = unsigned char>
61
+ struct BitArray {
62
+ static const int bits_per_addr = (int)sizeof(ContainerT) * CHAR_BIT;
63
+ ContainerT buf[(MAX_SIZE + bits_per_addr - 1) / bits_per_addr];
64
+ void set(const bool &new_bit = false) {
65
+ std::memset(buf, (new_bit ? (~0) : 0), sizeof(buf));
66
+ }
67
+ void reset() {set(false);}
68
+ void clear() {reset();}
69
+
70
+ bool operator[](const int &idx) const {
71
+ if((idx < 0) || (idx >= MAX_SIZE)){return false;}
72
+ const_div_t<bits_per_addr> qr(idx);
73
+ ContainerT mask((ContainerT)1 << qr.rem);
74
+ return buf[qr.quot] & mask;
75
+ }
76
+ void set(const int &idx, const bool &bit = true) {
77
+ if((idx < 0) || (idx >= MAX_SIZE)){return;}
78
+ const_div_t<bits_per_addr> qr(idx);
79
+ ContainerT mask((ContainerT)1 << qr.rem);
80
+ bit ? (buf[qr.quot] |= mask) : (buf[qr.quot] &= ~mask);
81
+ }
82
+ void reset(const int &idx) {
83
+ set(idx, false);
84
+ }
85
+ /**
86
+ * Generate bit pattern with arbitrary start and end indices
87
+ */
88
+ unsigned int pattern(const int &idx_lsb, int idx_msb) const {
89
+ if((idx_msb < idx_lsb) || (idx_lsb < 0) || (idx_msb >= MAX_SIZE)){
90
+ return 0;
91
+ }
92
+ static const int res_bits((int)sizeof(unsigned int) * CHAR_BIT);
93
+ if((idx_msb - idx_lsb) >= res_bits){
94
+ // check output boundary; if overrun, msb will be truncated.
95
+ idx_msb = idx_lsb + res_bits - 1;
96
+ }
97
+
98
+ const_div_t<bits_per_addr> qr_lsb(idx_lsb), qr_msb(idx_msb);
99
+ if(res_bits > bits_per_addr){
100
+ unsigned int res(buf[qr_msb.quot] & ((qr_msb.rem == bits_per_addr - 1)
101
+ ? ~((ContainerT)0)
102
+ : (((ContainerT)1 << (qr_msb.rem + 1)) - 1))); // MSB byte
103
+ if(qr_msb.quot > qr_lsb.quot){
104
+ for(int i(qr_msb.quot - 1); i > qr_lsb.quot; --i){ // Fill intermediate
105
+ res <<= bits_per_addr;
106
+ res |= buf[i];
107
+ }
108
+ res <<= (bits_per_addr - qr_lsb.rem);
109
+ res |= (buf[qr_lsb.quot] >> qr_lsb.rem); // Last byte
110
+ }else{
111
+ res >>= qr_lsb.rem;
112
+ }
113
+ return res;
114
+ }else{
115
+ ContainerT res(buf[qr_msb.quot] & ((qr_msb.rem == bits_per_addr - 1)
116
+ ? ~((ContainerT)0)
117
+ : (((ContainerT)1 << (qr_msb.rem + 1)) - 1))); // MSB byte
118
+ if(qr_msb.quot > qr_lsb.quot){
119
+ res <<= (bits_per_addr - qr_lsb.rem);
120
+ res |= (buf[qr_lsb.quot] >> qr_lsb.rem); // Last byte
121
+ }else{
122
+ res >>= qr_lsb.rem;
123
+ }
124
+ return (unsigned int)res;
125
+ }
126
+ }
127
+ std::vector<int> indices_one() const {
128
+ std::vector<int> res;
129
+ int idx(0);
130
+ static const const_div_t<bits_per_addr> qr(MAX_SIZE);
131
+ int rem(qr.rem);
132
+ for(int i(0); i < qr.quot; ++i, idx += bits_per_addr){
133
+ int idx2(idx);
134
+ for(ContainerT temp(buf[i]); temp > 0; temp >>= 1, ++idx2){
135
+ if(temp & 0x1){res.push_back(idx2);}
136
+ }
137
+ }
138
+ for(ContainerT temp(buf[qr.quot + 1]); (temp > 0) && (rem > 0); --rem, ++idx, temp >>= 1){
139
+ if(temp & 0x1){res.push_back(idx);}
140
+ }
141
+ return res;
142
+ }
143
+ };
144
+
145
+ #endif /* __BIT_ARRAY_H__ */
@@ -0,0 +1,558 @@
1
+ /*
2
+ * Copyright (c) 2015, M.Naruoka (fenrir)
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ *
8
+ * - Redistributions of source code must retain the above copyright notice,
9
+ * this list of conditions and the following disclaimer.
10
+ * - Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the documentation
12
+ * and/or other materials provided with the distribution.
13
+ * - Neither the name of the naruoka.org nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software
15
+ * without specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
21
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ *
30
+ */
31
+
32
+ #ifndef __COMPLEX_H
33
+ #define __COMPLEX_H
34
+
35
+ #include <exception>
36
+ #include <string>
37
+
38
+ #include <cmath>
39
+ #include <limits>
40
+
41
+ #if (__cplusplus < 201103L) && !defined(noexcept)
42
+ #define noexcept throw()
43
+ #endif
44
+
45
+ /** @file
46
+ * @brief ���f�����C�u����
47
+ *
48
+ * ���f�����`�������C�u�����B
49
+ * �����N������Ă������悤�Ȋ����ɂȂ�Ǝv����B
50
+ */
51
+
52
+ /**
53
+ * @brief ���f��
54
+ *
55
+ * ���f��������킷�N���X�ł��B
56
+ *
57
+ * @param FloatT ���Z���x�Adouble�Ȃ�
58
+ */
59
+ template <class FloatT>
60
+ class Complex{
61
+ private:
62
+ FloatT m_Real; ///< ����
63
+ FloatT m_Imaginary; ///< ����
64
+ public:
65
+ /**
66
+ * �R���X�g���N�^�B
67
+ *
68
+ * @param real ������
69
+ * @param imaginary ������
70
+ */
71
+ Complex(const FloatT &real, const FloatT &imaginary) noexcept
72
+ : m_Real(real), m_Imaginary(imaginary){}
73
+
74
+ /**
75
+ * �R���X�g���N�^�B
76
+ * ��������0�ŏ���������܂��B
77
+ *
78
+ * @param real ������
79
+ */
80
+ Complex(const FloatT &real) noexcept : m_Real(real), m_Imaginary(0){}
81
+
82
+ /**
83
+ * �R���X�g���N�^�B
84
+ * �������A�������Ƃ���0�ɏ���������܂��B
85
+ *
86
+ */
87
+ Complex() noexcept : m_Real(0), m_Imaginary(0){}
88
+
89
+ /**
90
+ * �f�X�g���N�^�B
91
+ *
92
+ */
93
+ ~Complex() noexcept {}
94
+
95
+ static Complex<FloatT> polar(const FloatT &r, const FloatT &theta = FloatT(0)){
96
+ return Complex<FloatT>(r * std::cos(theta), r * std::sin(theta));
97
+ }
98
+
99
+ /**
100
+ * ��������Ԃ��܂��B
101
+ *
102
+ * @return (FloatT) ������
103
+ */
104
+ const FloatT &real() const noexcept {return m_Real;}
105
+ FloatT &real() noexcept {
106
+ return const_cast<FloatT &>(static_cast<const Complex &>(*this).real());
107
+ }
108
+ /**
109
+ * ��������Ԃ��܂��B
110
+ *
111
+ * @return (FloatT) ������
112
+ */
113
+ const FloatT &imaginary() const noexcept {return m_Imaginary;}
114
+ FloatT &imaginary() noexcept {
115
+ return const_cast<FloatT &>(static_cast<const Complex &>(*this).imaginary());
116
+ }
117
+
118
+ Complex<FloatT> &operator=(const Complex<FloatT> &another) noexcept {
119
+ m_Real = another.m_Real;
120
+ m_Imaginary = another.m_Imaginary;
121
+ return *this;
122
+ }
123
+ Complex<FloatT> &operator=(const FloatT &another) noexcept {
124
+ m_Real = another;
125
+ m_Imaginary = 0;
126
+ return *this;
127
+ }
128
+
129
+ protected:
130
+ #if (__cplusplus < 201103L)
131
+ // @see https://stackoverflow.com/a/411781
132
+ template <class T = FloatT, bool has_infinity = std::numeric_limits<T>::has_infinity>
133
+ struct check_infinity_t;
134
+ template <class T>
135
+ struct check_infinity_t<T, true> {
136
+ static bool isinf(const Complex<T> &value) noexcept {
137
+ return (value.m_Real == std::numeric_limits<T>::infinity())
138
+ || (value.m_Real == -std::numeric_limits<T>::infinity())
139
+ || (value.m_Imaginary == std::numeric_limits<T>::infinity())
140
+ || (value.m_Imaginary == -std::numeric_limits<T>::infinity());
141
+ }
142
+ };
143
+ #else
144
+ template <class T = FloatT>
145
+ struct check_infinity_t {
146
+ static bool isinf(const Complex<T> &value) noexcept {
147
+ return std::isinf(value.m_Real) || std::isinf(value.m_Imaginary);
148
+ }
149
+ };
150
+ #endif
151
+
152
+ public:
153
+ bool isinf() const noexcept {
154
+ return check_infinity_t<>::isinf(*this);
155
+ }
156
+ bool isfinite() const noexcept {
157
+ return !isinf();
158
+ }
159
+
160
+ /**
161
+ * ��Βl�̓���Ԃ��܂��B
162
+ * std::pow(real(), 2) + std::pow(imaginary(), 2)�����Ă��܂��B
163
+ *
164
+ * @return (FloatT) ��Βl�̓��
165
+ * @see pow(FloatT, FloatT)
166
+ */
167
+ FloatT abs2() const noexcept {return std::pow(m_Real, 2) + std::pow(m_Imaginary, 2);}
168
+ /**
169
+ * ��Βl��Ԃ��܂��B
170
+ * sqrt(abs2())�����Ă��܂��B
171
+ *
172
+ * @return (FloatT) ��Βl
173
+ * @see abs2()
174
+ * @see sqrt()
175
+ */
176
+ FloatT abs() const {return std::sqrt(abs2());}
177
+ /**
178
+ * �Ίp��Ԃ��܂��B
179
+ *
180
+ * @return (double) �Ίp
181
+ */
182
+ double arg() const {
183
+ if((m_Real == FloatT(0)) && (m_Imaginary == FloatT(0))){
184
+ return 0;
185
+ }
186
+ return std::atan2(m_Imaginary, m_Real);
187
+ }
188
+ /**
189
+ * �w��悵�܂��B
190
+ * ��������`�Ƃ��āA���f����
191
+ * @f[
192
+ * a + b i = r e^{i \theta}
193
+ * @f]
194
+ * �Ƃ���킳���Ƃ��A
195
+ * @f[
196
+ * (a + b i)^{n} = r^{n} e^{i \theta n}
197
+ * @f]
198
+ * �Ƃ��܂��B
199
+ *
200
+ * @param factor �搔
201
+ * @return (Complex<FloatT>) ����
202
+ */
203
+ Complex<FloatT> power(const FloatT &factor) const {
204
+ if((m_Imaginary == FloatT(0)) && (m_Real >= FloatT(0))){
205
+ return Complex(std::pow(m_Real, factor));
206
+ }else{
207
+ FloatT _abs(std::pow(abs(), factor));
208
+ double _arg(arg() * factor);
209
+ return Complex(_abs * std::cos(_arg), _abs * std::sin(_arg));
210
+ }
211
+ }
212
+
213
+ /**
214
+ * �����������߂܂��B��`��power�ɏ]���܂��B
215
+ *
216
+ * @return (Complex<FloatT>) ����
217
+ * @see power
218
+ */
219
+ Complex<FloatT> sqrt() const {
220
+ return power(FloatT(0.5));
221
+ }
222
+
223
+ /**
224
+ * ���𕡑f����Ԃ��܂��B
225
+ *
226
+ * @return (Complex<FloatT>) ���𕡑f��
227
+ */
228
+ Complex<FloatT> conjugate() const noexcept {
229
+ Complex<FloatT> result = *this;
230
+ result.imaginary() *= -1;
231
+ return result;
232
+ }
233
+
234
+ /**
235
+ * ���������ǂ������ׂ܂��B
236
+ *
237
+ * @return (bool) �������ꍇtrue
238
+ */
239
+ bool operator==(const Complex<FloatT> &complex) const noexcept {
240
+ return m_Real == complex.real()
241
+ ? m_Imaginary == complex.imaginary()
242
+ : false;
243
+ }
244
+ /**
245
+ * �������Ȃ������ׂ܂��B
246
+ *
247
+ * @return (bool) �������Ȃ��ꍇtrue
248
+ */
249
+ bool operator!=(const Complex<FloatT> &complex) const noexcept {
250
+ return !(*this == complex);
251
+ }
252
+
253
+ /**
254
+ * ���Z���s���܂��B�j��I�ł��B
255
+ *
256
+ * @return (Complex<FloatT>) ���Z����
257
+ */
258
+ Complex<FloatT> &operator+=(const FloatT &scalar) noexcept {
259
+ m_Real += scalar;
260
+ return *this;
261
+ }
262
+ /**
263
+ * ���Z���s���܂��B
264
+ *
265
+ * @return (Complex<FloatT>) ���Z����
266
+ */
267
+ Complex<FloatT> operator+(const FloatT &scalar) const noexcept {
268
+ Complex<FloatT> result = *this;
269
+ return (result += scalar);
270
+ }
271
+ /**
272
+ * ���Z���s���܂��B
273
+ *
274
+ * @return (Complex<FloatT>) ���Z����
275
+ */
276
+ friend Complex<FloatT> operator+(const FloatT &scalar, const Complex<FloatT> complex) noexcept {return (complex + scalar);}
277
+
278
+ /**
279
+ * ���Z���s���܂��B�j��I�ł��B
280
+ *
281
+ * @return (Complex<FloatT>) ���Z����
282
+ */
283
+ Complex<FloatT> &operator-=(const FloatT &scalar) noexcept {return (*this) += (-scalar);}
284
+ /**
285
+ * ���Z���s���܂��B
286
+ *
287
+ * @return (Complex<FloatT>) ���Z����
288
+ */
289
+ Complex<FloatT> operator-(const FloatT &scalar) const noexcept {return (*this) + (-scalar);}
290
+ /**
291
+ * ���Z���s���܂��B
292
+ *
293
+ * @return (Complex<FloatT>) ���Z����
294
+ */
295
+ friend Complex<FloatT> operator-(const FloatT &scalar, const Complex<FloatT> complex) noexcept {return (complex - scalar);}
296
+
297
+ /**
298
+ * ��Z���s���܂��B�j��I�ł��B
299
+ *
300
+ * @return (Complex<FloatT>) ��Z����
301
+ */
302
+ Complex<FloatT> &operator *=(const FloatT &scalar) noexcept {
303
+ m_Real *= scalar;
304
+ m_Imaginary *= scalar;
305
+ return *this;
306
+ }
307
+ /**
308
+ * ��Z���s���܂��B
309
+ *
310
+ * @return (Complex<FloatT>) ��Z����
311
+ */
312
+ Complex<FloatT> operator*(const FloatT &scalar) const noexcept {
313
+ Complex<FloatT> result(*this);
314
+ return (result *= scalar);
315
+ }
316
+ /**
317
+ * ��Z���s���܂��B
318
+ *
319
+ * @return (Complex<FloatT>) ��Z����
320
+ */
321
+ friend Complex<FloatT> operator*(const FloatT &scalar, const Complex<FloatT> complex) noexcept {return (complex * scalar);}
322
+
323
+ /**
324
+ * ���Z���s���܂��B�j��I�ł��B
325
+ *
326
+ * @return (Complex<FloatT>) ���Z����
327
+ */
328
+ Complex<FloatT> &operator/=(const FloatT &scalar){return (*this) *= (1/scalar);}
329
+ /**
330
+ * ���Z���s���܂��B
331
+ *
332
+ * @return (Complex<FloatT>) ���Z����
333
+ */
334
+ Complex<FloatT> operator/(const FloatT &scalar) const{return (*this) * (1/scalar);}
335
+
336
+ /**
337
+ * �P���}�C�i�X�I�y���[�^�B
338
+ *
339
+ * @return (Complex<FloatT>) ����
340
+ */
341
+ Complex<FloatT> operator -() const noexcept {return ((*this) * -1);}
342
+
343
+ /**
344
+ * ���Z���s���܂��B�j��I�ł��B
345
+ *
346
+ * @return (Complex<FloatT>) ���Z����
347
+ */
348
+ Complex<FloatT> &operator+=(const Complex<FloatT> &complex) noexcept {
349
+ m_Real += complex.real();
350
+ m_Imaginary += complex.imaginary();
351
+ return *this;
352
+ }
353
+ /**
354
+ * ���Z���s���܂��B
355
+ *
356
+ * @return (Complex<FloatT>) ���Z����
357
+ */
358
+ Complex<FloatT> operator+(const Complex<FloatT> &complex) const noexcept {
359
+ Complex<FloatT> result = *this;
360
+ return (result += complex);
361
+ }
362
+
363
+ /**
364
+ * ���Z���s���܂��B�j��I�ł��B
365
+ *
366
+ * @return (Complex<FloatT>) ���Z����
367
+ */
368
+ Complex<FloatT> &operator-=(const Complex<FloatT> &complex) noexcept {
369
+ return ((*this) += (-complex));
370
+ }
371
+ /**
372
+ * ���Z���s���܂��B
373
+ *
374
+ * @return (Complex<FloatT>) ���Z����
375
+ */
376
+ Complex<FloatT> operator-(const Complex<FloatT> &complex) const noexcept {
377
+ return ((-complex) += (*this));
378
+ }
379
+
380
+ /**
381
+ * ��Z���s���܂��B
382
+ *
383
+ * @return (Complex<FloatT>) ��Z����
384
+ */
385
+ Complex<FloatT> operator*(const Complex<FloatT> &complex) const noexcept {
386
+ return Complex<FloatT>(
387
+ m_Real * complex.real() - m_Imaginary * complex.imaginary(),
388
+ m_Real * complex.imaginary() + m_Imaginary * complex.real());
389
+ }
390
+ /**
391
+ * ��Z���s���܂��B�j��I�ł��B
392
+ *
393
+ * @return (Complex<FloatT>) ��Z����
394
+ */
395
+ Complex<FloatT> &operator*=(const Complex<FloatT> &complex) noexcept {
396
+ Complex<FloatT> copy = *this;
397
+ m_Real =
398
+ copy.real() * complex.real()
399
+ - copy.imaginary() * complex.imaginary();
400
+ m_Imaginary =
401
+ copy.real() * complex.imaginary()
402
+ + copy.imaginary() * complex.real();
403
+ return *this;
404
+ }
405
+
406
+ /**
407
+ * ���Z���s���܂��B�j��I�ł��B
408
+ *
409
+ * @return (Complex<FloatT>) ���Z����
410
+ */
411
+ Complex<FloatT> &operator/=(const Complex<FloatT> &complex){
412
+ return (*this) *= (complex.conjugate() / complex.abs2());
413
+ }
414
+ /**
415
+ * ���Z���s���܂��B
416
+ *
417
+ * @return (Complex<FloatT>) ���Z����
418
+ */
419
+ Complex<FloatT> operator/(const Complex<FloatT> &complex) const{
420
+ Complex<FloatT> copy = (*this);
421
+ return (copy /= complex);
422
+ }
423
+
424
+ /**
425
+ * ���Z���s���܂��B
426
+ *
427
+ * @return (Complex<FloatT>) ���Z����
428
+ */
429
+ friend Complex<FloatT> operator/(const FloatT &scalar, const Complex<FloatT> complex){
430
+ return Complex<FloatT>(scalar) / complex;
431
+ }
432
+
433
+ /**
434
+ * �݂₷���`�ŕ��f�����o�͂��܂��B
435
+ *
436
+ * @param out �o�̓X�g���[��
437
+ * @param complex �o�͂��镡�f��
438
+ */
439
+ friend std::ostream &operator<<(std::ostream &out, const Complex<FloatT> &complex){
440
+ out << complex.real() << " + "
441
+ << complex.imaginary() << "i";
442
+ return out;
443
+ }
444
+
445
+ /**
446
+ * e�̎w��������߂܂��B
447
+ *
448
+ * @param imaginary ����
449
+ * @return (Complex<FloatT>) ����
450
+ */
451
+ static Complex<FloatT> exp(const FloatT &imaginary) noexcept {
452
+ return Complex<FloatT>(std::cos(imaginary), std::sin(imaginary));
453
+ }
454
+
455
+ /**
456
+ * e�̎w��������߂܂��B
457
+ *
458
+ * @param real ����
459
+ * @param imaginary ����
460
+ * @return (Complex<FloatT>) ����
461
+ */
462
+ static Complex<FloatT> exp(const FloatT &real, const FloatT &imaginary) noexcept {
463
+ return Complex<FloatT>::exp(imaginary) *= std::exp(real);
464
+ }
465
+
466
+ /**
467
+ * e�̎w��������߂܂��B
468
+ *
469
+ * @param complex ���f��
470
+ * @return (Complex<FloatT>) ����
471
+ */
472
+ static Complex<FloatT> exp(const Complex<FloatT> &complex) noexcept {
473
+ return Complex<FloatT>::exp(
474
+ complex.real(), complex.imaginary());
475
+ }
476
+ };
477
+
478
+ /**
479
+ * exp�̕��f���g��
480
+ *
481
+ * @param real ����
482
+ * @param imaginary ����
483
+ * @param FloatT ���Z���x
484
+ * @return (Complex<FloatT>) ����
485
+ */
486
+ template <class FloatT>
487
+ inline Complex<FloatT> iexp(const FloatT &real, const FloatT &imaginary) noexcept {
488
+ return Complex<FloatT>::exp(real, imaginary);
489
+ }
490
+
491
+ /**
492
+ * exp�̕��f���g��
493
+ * @param imaginary ����
494
+ * @param FloatT ���Z���x
495
+ * @return (Complex<FloatT>) ����
496
+ */
497
+ template <class FloatT>
498
+ inline Complex<FloatT> iexp(const FloatT &imaginary) noexcept {
499
+ return Complex<FloatT>::exp(imaginary);
500
+ }
501
+
502
+ namespace std {
503
+
504
+ /**
505
+ * exp�̕��f���g��
506
+ *
507
+ * @param complex ���f��
508
+ * @param FloatT ���Z���x
509
+ * @return (Complex<FloatT>) ����
510
+ */
511
+ template <class FloatT>
512
+ inline Complex<FloatT> exp(const Complex<FloatT> &complex) noexcept {
513
+ return Complex<FloatT>::exp(complex);
514
+ }
515
+
516
+ /**
517
+ * pow�̕��f���g��
518
+ *
519
+ * @param complex ���f��
520
+ * @param FloatT ���Z���x
521
+ * @return (Complex<FloatT>) ����
522
+ */
523
+ template <class FloatT>
524
+ inline Complex<FloatT> pow(const Complex<FloatT> &complex, const FloatT &factor) noexcept {
525
+ return complex.power(factor);
526
+ }
527
+
528
+ /**
529
+ * sqrt�̕��f���g��
530
+ *
531
+ * @param complex ���f��
532
+ * @param FloatT ���Z���x
533
+ * @return (Complex<FloatT>) ����
534
+ */
535
+ template <class FloatT>
536
+ inline Complex<FloatT> sqrt(const Complex<FloatT> &complex){
537
+ return complex.sqrt();
538
+ }
539
+
540
+ /**
541
+ * Calculate absolute value of a complex value
542
+ *
543
+ * @param complex target
544
+ * @param FloatT precision
545
+ * @return (Complex<FloatT>) result
546
+ */
547
+ template <class FloatT>
548
+ inline FloatT abs(const Complex<FloatT> &complex) noexcept {
549
+ return complex.abs();
550
+ }
551
+
552
+ } // namespace
553
+
554
+ #if (__cplusplus < 201103L) && defined(noexcept)
555
+ #undef noexcept
556
+ #endif
557
+
558
+ #endif /* __COMPLEX_H */