cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
div.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_COMPLEX_FUNCTIONS_DIV_H
4#define pRC_CORE_COMPLEX_FUNCTIONS_DIV_H
5
8
9namespace pRC
10{
11 template<IsComplex TA, IsComplex TB>
12 static inline constexpr auto operator/(TA const &a, TB const &b)
13 {
14 auto const denominator = rcp(norm<2, 1>(b));
15
16 auto const real =
17 (a.real() * b.real() + a.imag() * b.imag()) * denominator;
18 auto const imag =
19 (a.imag() * b.real() - a.real() * b.imag()) * denominator;
20
21 return Complex(real, imag);
22 }
23
24 template<IsComplex TA, IsValue TB>
25 static inline constexpr auto operator/(TA const &a, TB const &b)
26 {
27 auto const real = a.real() / b;
28 auto const imag = a.imag() / b;
29
30 return Complex(real, imag);
31 }
32
33 template<IsValue TA, IsComplex TB>
34 static inline constexpr auto operator/(TA const &a, TB const &b)
35 {
36 auto const denominator = rcp(norm<2, 1>(b));
37
38 auto const real = a * b.real() * denominator;
39 auto const imag = -a * b.imag() * denominator;
40
41 return Complex(real, imag);
42 }
43}
44#endif // pRC_CORE_COMPLEX_FUNCTIONS_DIV_H
Definition cholesky.hpp:10
static constexpr auto rcp(T const &b)
Definition rcp.hpp:12
Complex(T const &) -> Complex< T >
static constexpr decltype(auto) real(X &&a)
Definition real.hpp:12
static constexpr decltype(auto) imag(X &&a)
Definition imag.hpp:12
static constexpr auto operator/(Sequence< T, As... > const, Sequence< T, Bs... > const)
Definition sequence.hpp:179
static constexpr auto norm(T const &a)
Definition norm.hpp:12