cMHN 1.1
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
10
11namespace pRC
12{
13 template<class TA, class TB>
14 static inline constexpr auto operator/(Complex<TA> const &a,
15 Complex<TB> const &b)
16 {
17 auto const denominator = rcp(norm<2, 1>(b));
18
19 auto const real =
20 (a.real() * b.real() + a.imag() * b.imag()) * denominator;
21 auto const imag =
22 (a.imag() * b.real() - a.real() * b.imag()) * denominator;
23
24 return Complex(real, imag);
25 }
26
27 template<class TA, class TB, If<IsValue<TB>> = 0,
28 If<IsInvocable<Div, TA, TB>> = 0>
29 static inline constexpr auto operator/(Complex<TA> const &a, TB const &b)
30 {
31 auto const real = a.real() / b;
32 auto const imag = a.imag() / b;
33
34 return Complex(real, imag);
35 }
36
37 template<class TA, class TB, If<IsValue<TA>> = 0>
38 static inline constexpr auto operator/(TA const &a, Complex<TB> const &b)
39 {
40 auto const denominator = rcp(norm<2, 1>(b));
41
42 auto const real = a * b.real() * denominator;
43 auto const imag = -a * b.imag() * denominator;
44
45 return Complex(real, imag);
46 }
47}
48#endif // pRC_CORE_COMPLEX_FUNCTIONS_DIV_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 auto rcp(Complex< T > const &b)
Definition rcp.hpp:13
static constexpr decltype(auto) imag(X &&a)
Definition imag.hpp:11
static constexpr decltype(auto) real(X &&a)
Definition real.hpp:11
static constexpr auto operator/(Sequence< T, As... > const, Sequence< T, Bs... > const)
Definition sequence.hpp:169
Complex(T const &) -> Complex< T >