b2api
B2000++ API Reference Manual, VERSION 4.6
 
Loading...
Searching...
No Matches
b2csda.H
Go to the documentation of this file.
1//------------------------------------------------------------------------
2// b2csda.H --
3//
4//
5// written by Thomas Ludwig
6//
7// Copyright (c) 2017
8// SMR Engineering & Development SA
9// 2502 Bienne, Switzerland
10//
11// All Rights Reserved. Proprietary source code. The contents of
12// this file may not be disclosed to third parties, copied or
13// duplicated in any form, in whole or in part, without the prior
14// written permission of SMR.
15//------------------------------------------------------------------------
16
17#ifndef _B2_CSDA_H_
18#define _B2_CSDA_H_
19
20#include <complex>
21#include <limits>
22
35
36// start of namespace b2000
37namespace b2000 {
38namespace details {
39
40template <typename T>
41class csda : public std::complex<T> {
42public:
43 using std::complex<T>::complex;
44
45 csda(const std::complex<T>& a) : std::complex<T>(a) {}
46
47 operator T() const { return this->real(); }
48
49 csda<T>& operator=(const T& a) {
50 ((std::complex<T>&)*this) = a;
51 return *this;
52 }
53
54 csda<T>& operator+=(const T& a) {
55 ((std::complex<T>&)*this) += a;
56 return *this;
57 }
58
59 csda<T>& operator-=(const T& a) {
60 ((std::complex<T>&)*this) -= a;
61 return *this;
62 }
63
64 csda<T>& operator*=(const T& a) {
65 ((std::complex<T>&)*this) *= a;
66 return *this;
67 }
68
69 csda<T>& operator/=(const T& a) {
70 ((std::complex<T>&)*this) /= a;
71 return *this;
72 }
73
74 template <typename X>
75 csda<T>& operator=(const std::complex<X>& a) {
76 ((std::complex<T>&)*this) = a;
77 return *this;
78 }
79
80 template <typename X>
81 csda<T>& operator+=(const std::complex<X>& a) {
82 ((std::complex<T>&)*this) += a;
83 return *this;
84 }
85
86 template <typename X>
87 csda<T>& operator-=(const std::complex<X>& a) {
88 ((std::complex<T>&)*this) -= a;
89 return *this;
90 }
91
92 template <typename X>
93 csda<T>& operator*=(const std::complex<X>& a) {
94 ((std::complex<T>&)*this) *= a;
95 return *this;
96 }
97
98 template <typename X>
99 csda<T>& operator/=(const std::complex<X>& a) {
100 ((std::complex<T>&)*this) /= a;
101 return *this;
102 }
103};
104
105template <typename T>
106inline csda<T> operator+(csda<T> a, const csda<T>& b) {
107 return a += b;
108}
109
110template <typename T>
111inline csda<T> operator+(csda<T> a, const T& b) {
112 return a += b;
113}
114
115template <
116 typename T1, typename T2, class = typename std::enable_if<std::is_integral<T2>::value>::type>
117inline csda<T1> operator+(csda<T1> a, const T2& b) {
118 return a += b;
119}
120
121template <typename T>
122inline const csda<T> operator+(const T& a, csda<T> b) {
123 return b += a;
124}
125
126template <
127 typename T1, typename T2, class = typename std::enable_if<std::is_integral<T1>::value>::type>
128inline csda<T2> operator+(const T1& a, csda<T2> b) {
129 return b += a;
130}
131
132template <typename T>
133inline csda<T> operator-(csda<T> a, const csda<T>& b) {
134 return a -= b;
135}
136
137template <typename T>
138inline csda<T> operator-(csda<T> a, const T& b) {
139 return a -= b;
140}
141
142template <
143 typename T1, typename T2, class = typename std::enable_if<std::is_integral<T2>::value>::type>
144inline csda<T1> operator-(csda<T1> a, const T2& b) {
145 return a -= b;
146}
147
148template <typename T>
149inline const csda<T> operator-(const T& a, const csda<T>& b) {
150 return csda<T>(a) -= b;
151}
152
153template <
154 typename T1, typename T2, class = typename std::enable_if<std::is_integral<T1>::value>::type>
155inline const csda<T2> operator-(const T1& a, const csda<T2>& b) {
156 return csda<T2>(a) -= b;
157}
158
159template <typename T>
160inline csda<T> operator*(csda<T> a, const csda<T>& b) {
161 return a *= b;
162}
163
164template <typename T>
165inline csda<T> operator*(csda<T> a, const T& b) {
166 return a *= b;
167}
168
169template <
170 typename T1, typename T2, class = typename std::enable_if<std::is_integral<T2>::value>::type>
171inline csda<T1> operator*(csda<T1> a, const T2& b) {
172 return a *= b;
173}
174
175template <typename T>
176inline csda<T> operator*(const T& a, csda<T> b) {
177 return b *= a;
178}
179
180template <
181 typename T1, typename T2, class = typename std::enable_if<std::is_integral<T1>::value>::type>
182inline csda<T2> operator*(const T1& a, csda<T2> b) {
183 return b *= a;
184}
185
186template <typename T>
187inline csda<T> operator/(csda<T> a, const csda<T>& b) {
188 return a /= b;
189}
190
191template <typename T>
192inline csda<T> operator/(csda<T> a, const T& b) {
193 return a /= b;
194}
195
196template <
197 typename T1, typename T2, class = typename std::enable_if<std::is_integral<T2>::value>::type>
198inline const csda<T1> operator/(csda<T1> a, const T2& b) {
199 return a /= b;
200}
201
202template <typename T>
203inline const csda<T> operator/(const T& a, const csda<T>& b) {
204 return csda<T>(a) /= b;
205}
206
207template <
208 typename T1, typename T2, class = typename std::enable_if<std::is_integral<T1>::value>::type>
209inline const csda<T2> operator/(const T1& a, const csda<T2>& b) {
210 return csda<T2>(a) /= b;
211}
212
213template <typename T>
214inline const csda<T> operator+(const csda<T>& a) {
215 return a;
216}
217
219template <typename T>
220inline const csda<T> operator-(const csda<T>& a) {
221 return -std::complex<T>(a);
222}
223
225template <typename T1, typename T2>
226inline bool operator==(const csda<T1>& a, const csda<T2>& b) {
227 return real(a) == real(b);
228}
229
231template <typename T1, typename T2>
232inline bool operator==(const csda<T1>& a, const T2& b) {
233 return real(a) == b;
234}
235
237template <typename T1, typename T2>
238inline bool operator==(const T1& a, const csda<T2>& b) {
239 return a == real(b);
240}
241
243template <typename T1, typename T2>
244inline bool operator!=(const csda<T1>& a, const csda<T2>& b) {
245 return real(a) != real(b);
246}
247
249template <typename T1, typename T2>
250inline bool operator!=(const csda<T1>& a, const T2& b) {
251 return real(a) != b;
252}
253
255template <typename T1, typename T2>
256inline bool operator!=(const T1& a, const csda<T2>& b) {
257 return a != real(b);
258}
259
261template <typename T1, typename T2>
262inline bool operator<(const csda<T1>& a, const csda<T2>& b) {
263 return real(a) < real(b);
264}
265
267template <typename T1, typename T2>
268inline bool operator<(const csda<T1>& a, const T2& b) {
269 return real(a) < b;
270}
271
273template <typename T1, typename T2>
274inline bool operator<(const T1& a, const csda<T2>& b) {
275 return a < real(b);
276}
277
279template <typename T1, typename T2>
280inline bool operator>(const csda<T1>& a, const csda<T2>& b) {
281 return real(a) > real(b);
282}
283
285template <typename T1, typename T2>
286inline bool operator>(const csda<T1>& a, const T2& b) {
287 return real(a) > b;
288}
289
291template <typename T1, typename T2>
292inline bool operator>(const T1& a, const csda<T2>& b) {
293 return a > real(b);
294}
295
297template <typename T1, typename T2>
298inline bool operator<=(const csda<T1>& a, const csda<T2>& b) {
299 return real(a) <= real(b);
300}
301
303template <typename T1, typename T2>
304inline bool operator<=(const csda<T1>& a, const T2& b) {
305 return real(a) <= b;
306}
307
309template <typename T1, typename T2>
310inline bool operator<=(const T1& a, const csda<T2>& b) {
311 return a <= real(b);
312}
313
315template <typename T1, typename T2>
316inline bool operator>=(const csda<T1>& a, const csda<T2>& b) {
317 return real(a) >= real(b);
318}
319
321template <typename T1, typename T2>
322inline bool operator>=(const csda<T1>& a, const T2& b) {
323 return real(a) >= b;
324}
325
327template <typename T1, typename T2>
328inline bool operator>=(const T1& a, const csda<T2>& b) {
329 return a >= real(b);
330}
331
334template <typename T>
335inline csda<T> abs(const csda<T>& a) {
336 if (real(a) < 0) { return -std::complex<T>(a); }
337 return a;
338}
339
342template <typename T>
343inline csda<T> norm(const csda<T>& a) {
344 return a * a;
345}
346
348template <typename T>
349inline csda<T> conj(const csda<T>& a) {
350 return a;
351}
352
353template <typename T>
354inline csda<T> proj(const csda<T>& a) {
355 return std::proj(std::complex<T>(a));
356}
357
359template <typename T>
360inline csda<T> exp(const csda<T>& a) {
361 return std::exp(std::complex<T>(a));
362}
363
365template <typename T>
366inline csda<T> log(const csda<T>& a) {
367 return std::log(std::complex<T>(a));
368}
369
371template <typename T>
372inline csda<T> log10(const csda<T>& a) {
373 return std::log10(std::complex<T>(a));
374}
375
377template <typename T>
378inline csda<T> pow(const csda<T>& a, const csda<T>& b) {
379 return std::pow(std::complex<T>(a), std::complex<T>(b));
380}
381
383template <typename T1, typename T2>
384inline csda<T1> pow(const csda<T1>& a, const T2& b) {
385 return std::pow(std::complex<T1>(a), b);
386}
387
389template <typename T1, typename T2>
390inline csda<T2> pow(const T1& a, const csda<T2>& b) {
391 return std::pow(a, std::complex<T2>(b));
392}
393
395template <typename T>
396inline csda<T> sqrt(const csda<T>& a) {
397 return std::sqrt(std::complex<T>(a));
398}
399
401template <typename T>
402inline csda<T> sin(const csda<T>& a) {
403 const T& x = a.real();
404 const T& y = a.imag();
405 return csda<T>(std::sin(x) * std::cosh(y), std::cos(x) * std::sinh(y));
406}
407
409template <typename T>
410inline csda<T> cos(const csda<T>& a) {
411 const T& x = a.real();
412 const T& y = a.imag();
413 return csda<T>(std::cos(x) * std::cosh(y), -std::sin(x) * std::sinh(y));
414}
415
417template <typename T>
418inline csda<T> tan(const csda<T>& a) {
419 return std::tan(std::complex<T>(a));
420}
421
423template <typename T>
424inline csda<T> asin(const csda<T>& z) {
425 csda<T> u = -std::log(csda<T>(0, z) + std::sqrt(1 - z * z));
426 return csda<T>(u.imag(), u.real());
427}
428
430template <typename T>
431inline csda<T> acos(const csda<T>& z) {
432 csda<T> u = -std::log(z + std::sqrt(z * z - 1));
433 return csda<T>(u.imag(), u.real());
434}
435
437template <typename T>
438inline csda<T> atan(const csda<T>& a) {
439 return std::atan(std::complex<T>(a));
440}
441
443template <typename T>
444inline csda<T> sinh(const csda<T>& a) {
445 return std::sinh(std::complex<T>(a));
446}
447
449template <typename T>
450inline csda<T> cosh(const csda<T>& a) {
451 return std::cosh(std::complex<T>(a));
452}
453
455template <typename T>
456inline csda<T> tanh(const csda<T>& a) {
457 return std::tanh(std::complex<T>(a));
458}
459
461template <typename T>
462inline csda<T> asinh(const csda<T>& a) {
463 return std::asinh(std::complex<T>(a));
464}
465
467template <typename T>
468inline csda<T> acosh(const csda<T>& a) {
469 return std::acosh(std::complex<T>(a));
470}
471
473template <typename T>
474inline csda<T> atanh(const csda<T>& a) {
475 return std::atanh(std::complex<T>(a));
476}
477} // end namespace details
478using details::csda;
479} // end namespace b2000
480
481// define class for numeric_limits for the
482// csda data type.
483template <typename T>
484class std::numeric_limits<b2000::csda<T> > {
485public:
486 static constexpr bool is_specialized = true;
487 static constexpr bool is_signed = true;
488 static constexpr bool is_integer = false;
489 static constexpr bool is_exact = numeric_limits<T>::is_exact;
490 static constexpr bool has_infinity = numeric_limits<T>::has_infinity;
491 static constexpr bool has_quiet_NaN = numeric_limits<T>::has_quiet_NaN;
492 static constexpr bool has_signaling_NaN = numeric_limits<T>::has_signaling_NaN;
493 static constexpr bool has_denorm = numeric_limits<T>::has_denorm;
494 static constexpr bool has_denorm_loss = numeric_limits<T>::has_denorm_loss;
495 static constexpr float_round_style round_style = numeric_limits<T>::round_style;
496 static constexpr bool is_iec559 = numeric_limits<T>::is_iec559;
497 static constexpr bool is_bounded = numeric_limits<T>::is_bounded;
498 static constexpr bool is_modulo = numeric_limits<T>::is_modulo;
499 static constexpr int digits = numeric_limits<T>::digits;
500 static constexpr int digits10 = numeric_limits<T>::digits10;
501 static constexpr int max_digits10 = numeric_limits<T>::max_digits10;
502 static constexpr int radix = numeric_limits<T>::radix;
503 static constexpr int min_exponent = numeric_limits<T>::min_exponent;
504 static constexpr int min_exponent10 = numeric_limits<T>::min_exponent10;
505 static constexpr int max_exponent = numeric_limits<T>::max_exponent;
506 static constexpr int max_exponent10 = numeric_limits<T>::max_exponent10;
507 static constexpr bool traps = numeric_limits<T>::traps;
508 static constexpr bool tinyness_before = numeric_limits<T>::tinyness_before;
509
510 static constexpr b2000::csda<T> min() { return b2000::csda<T>(numeric_limits<T>::min()); }
511
512 static constexpr b2000::csda<T> lowest() { return b2000::csda<T>(numeric_limits<T>::lowest()); }
513
514 static constexpr b2000::csda<T> max() { return b2000::csda<T>(numeric_limits<T>::max()); }
515
516 static constexpr b2000::csda<T> epsilon() {
517 return b2000::csda<T>(numeric_limits<T>::epsilon());
518 }
519
520 static constexpr b2000::csda<T> round_error() {
521 return b2000::csda<T>(numeric_limits<T>::round_error());
522 }
523
524 static constexpr b2000::csda<T> infinity() {
525 return b2000::csda<T>(numeric_limits<T>::infinity());
526 }
527
528 static constexpr b2000::csda<T> quiet_NaN() {
529 return b2000::csda<T>(numeric_limits<T>::quiet_NaN());
530 }
531
532 static constexpr b2000::csda<T> signaling_NaN() {
533 return b2000::csda<T>(numeric_limits<T>::signaling_NaN());
534 }
535
536 static constexpr b2000::csda<T> denorm_min() {
537 return b2000::csda<T>(numeric_limits<T>::denorm_min());
538 }
539};
540
541template <typename T>
542class std::numeric_limits<const b2000::csda<T> > : public std::numeric_limits<b2000::csda<T> > {};
543
544template <typename T>
545class std::numeric_limits<volatile b2000::csda<T> > : public std::numeric_limits<b2000::csda<T> > {
546};
547
548template <typename T>
549class std::numeric_limits<const volatile b2000::csda<T> >
550 : public std::numeric_limits<b2000::csda<T> > {};
551
552#endif /* _B2_CSDA_H_ */
csda< T > acos(const csda< T > &z)
Arc cosine of a csda number.
Definition b2csda.H:431
csda< T > sinh(const csda< T > &a)
Hyperbolic sine of a csda number.
Definition b2csda.H:444
csda< T > sin(const csda< T > &a)
Sine of a csda number.
Definition b2csda.H:402
csda< T > log10(const csda< T > &a)
Common logarithm of a csda number.
Definition b2csda.H:372
csda< T > log(const csda< T > &a)
Natural logarithm of a csda number.
Definition b2csda.H:366
csda< T > exp(const csda< T > &a)
Natural exponential of a csda number.
Definition b2csda.H:360
csda< T > abs(const csda< T > &a)
Definition b2csda.H:335
csda< T > tan(const csda< T > &a)
Tangent of a csda number.
Definition b2csda.H:418
bool operator>=(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:316
csda< T > sqrt(const csda< T > &a)
Square root of a csda number.
Definition b2csda.H:396
csda< T > pow(const csda< T > &a, const csda< T > &b)
Power from two csda numbers.
Definition b2csda.H:378
csda< T > cosh(const csda< T > &a)
Hyperbolic cosine of a csda number.
Definition b2csda.H:450
bool operator<=(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:298
csda< T > atanh(const csda< T > &a)
Area hyperbolic tangent of a csda number.
Definition b2csda.H:474
csda< T > norm(const csda< T > &a)
Definition b2csda.H:343
csda< T > cos(const csda< T > &a)
Cosine of a csda number.
Definition b2csda.H:410
csda< T > asin(const csda< T > &z)
Arc sine of a csda number.
Definition b2csda.H:424
csda< T > acosh(const csda< T > &a)
Area hyperbolic cosine of a csda number.
Definition b2csda.H:468
bool operator==(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:226
csda< T > tanh(const csda< T > &a)
Tangent of a csda number.
Definition b2csda.H:456
bool operator>(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:280
csda< T > asinh(const csda< T > &a)
Area hyperbolic sine of a csda number.
Definition b2csda.H:462
bool operator!=(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:244
bool operator<(const csda< T1 > &a, const csda< T2 > &b)
Comparison of two csda numbers is performed on the real part only.
Definition b2csda.H:262
csda< T > conj(const csda< T > &a)
Returns the csda number rather than the std::complex conjugate.
Definition b2csda.H:349
csda< T > atan(const csda< T > &a)
Arc tangent of a csda number.
Definition b2csda.H:438
Contains the base classes for implementing Finite Elements.
Definition b2boundary_condition.H:32