From a348bc3ffd501e6f76cf8f4f326ff62fe36a6f5b Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 2 Aug 2019 13:55:25 -0400 Subject: [PATCH] Introduce operator/ for complex numbers --- include/deal.II/base/complex_overloads.h | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/deal.II/base/complex_overloads.h b/include/deal.II/base/complex_overloads.h index e95bed9a95..81dd4d4a0b 100644 --- a/include/deal.II/base/complex_overloads.h +++ b/include/deal.II/base/complex_overloads.h @@ -45,6 +45,21 @@ operator*(const std::complex &left, const std::complex &right) return static_cast(left) * static_cast(right); } +/** + * Provide an operator/ that operates on mixed complex floating point + * types. Annoyingly, the standard library does not provide such an + * operator... + * + * @relatesalso ProductType + */ +template +typename ProductType, std::complex>::type inline +operator/(const std::complex &left, const std::complex &right) +{ + using result_type = + typename ProductType, std::complex>::type; + return static_cast(left) / static_cast(right); +} /** * Provide an operator* for a scalar multiplication of a complex @@ -63,6 +78,22 @@ operator*(const std::complex &left, const U &right) return static_cast(left) * static_cast(right); } +/** + * Provide an operator/ for a scalar division of a complex + * floating point type with a different real floating point type. Annoyingly, + * the standard library does not provide such an operator... + * + * @relatesalso EnableIfScalar + * @relatesalso ProductType + */ +template +typename ProductType, + typename EnableIfScalar::type>::type inline +operator/(const std::complex &left, const U &right) +{ + using result_type = typename ProductType, U>::type; + return static_cast(left) / static_cast(right); +} /** * Provide an operator* for a scalar multiplication of a real @@ -80,6 +111,23 @@ operator*(const T &left, const std::complex &right) using result_type = typename ProductType, U>::type; return static_cast(left) * static_cast(right); } + +/** + * Provide an operator/ for a scalar division of a real + * floating point type with a different complex floating point type. + * Annoyingly, the standard library does not provide such an operator... + * + * @relatesalso EnableIfScalar + * @relatesalso ProductType + */ +template +typename ProductType::type, + std::complex>::type inline +operator/(const T &left, const std::complex &right) +{ + using result_type = typename ProductType, U>::type; + return static_cast(left) / static_cast(right); +} #endif /* DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS */ DEAL_II_NAMESPACE_CLOSE -- 2.39.5