cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
sqrt.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_COMPLEX_FUNCTIONS_SQRT_H
4#define pRC_CORE_COMPLEX_FUNCTIONS_SQRT_H
5
8
9namespace pRC
10{
11 template<class T>
12 static inline constexpr auto sqrt(Complex<T> const &a)
13 {
14 if(a.real() == zero())
15 {
16 auto const t = sqrt(abs(a.imag()) / identity<T>(2));
17 if(a.imag() < zero())
18 {
19 return Complex(t, -t);
20 }
21 else
22 {
23 return Complex(t, t);
24 }
25 }
26 else
27 {
28 auto const t = sqrt(identity<T>(2) * (abs(a) + abs(a.real())));
29 auto const t2 = t / identity<T>(2);
30 auto const at = a.imag() / t;
31
32 if(a.real() > zero())
33 {
34 return Complex(t2, at);
35 }
36 else
37 {
38 auto const real = abs(at);
39 if(a.imag() < zero())
40 {
41 return Complex(real, -t2);
42 }
43 else
44 {
45 return Complex(real, t2);
46 }
47 }
48 }
49 }
50}
51#endif // pRC_CORE_COMPLEX_FUNCTIONS_SQRT_H
Definition complex.hpp:26
constexpr decltype(auto) real() &&
Definition complex.hpp:125
constexpr decltype(auto) imag() &&
Definition complex.hpp:145
Definition cholesky.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static constexpr decltype(auto) real(X &&a)
Definition real.hpp:11
static constexpr auto zero()
Definition zero.hpp:12
static constexpr auto abs(Complex< T > const &a)
Definition abs.hpp:12
static constexpr auto sqrt(Complex< T > const &a)
Definition sqrt.hpp:12
Complex(T const &) -> Complex< T >