]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce operator/ for complex numbers
authorDaniel Arndt <arndtd@ornl.gov>
Fri, 2 Aug 2019 17:55:25 +0000 (13:55 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Fri, 2 Aug 2019 18:06:48 +0000 (14:06 -0400)
include/deal.II/base/complex_overloads.h

index e95bed9a951c59635d2e5735069b0b1c071aa9d7..81dd4d4a0b43ddae958fb67cc6251ca453ac59cf 100644 (file)
@@ -45,6 +45,21 @@ operator*(const std::complex<T> &left, const std::complex<U> &right)
   return static_cast<result_type>(left) * static_cast<result_type>(right);
 }
 
+/**
+ * Provide an <tt>operator/</tt> that operates on mixed complex floating point
+ * types. Annoyingly, the standard library does not provide such an
+ * operator...
+ *
+ * @relatesalso ProductType
+ */
+template <typename T, typename U>
+typename ProductType<std::complex<T>, std::complex<U>>::type inline
+operator/(const std::complex<T> &left, const std::complex<U> &right)
+{
+  using result_type =
+    typename ProductType<std::complex<T>, std::complex<U>>::type;
+  return static_cast<result_type>(left) / static_cast<result_type>(right);
+}
 
 /**
  * Provide an <tt>operator*</tt> for a scalar multiplication of a complex
@@ -63,6 +78,22 @@ operator*(const std::complex<T> &left, const U &right)
   return static_cast<result_type>(left) * static_cast<result_type>(right);
 }
 
+/**
+ * Provide an <tt>operator/</tt> 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 T, typename U>
+typename ProductType<std::complex<T>,
+                     typename EnableIfScalar<U>::type>::type inline
+operator/(const std::complex<T> &left, const U &right)
+{
+  using result_type = typename ProductType<std::complex<T>, U>::type;
+  return static_cast<result_type>(left) / static_cast<result_type>(right);
+}
 
 /**
  * Provide an <tt>operator*</tt> for a scalar multiplication of a real
@@ -80,6 +111,23 @@ operator*(const T &left, const std::complex<U> &right)
   using result_type = typename ProductType<std::complex<T>, U>::type;
   return static_cast<result_type>(left) * static_cast<result_type>(right);
 }
+
+/**
+ * Provide an <tt>operator/</tt> 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 T, typename U>
+typename ProductType<typename EnableIfScalar<T>::type,
+                     std::complex<U>>::type inline
+operator/(const T &left, const std::complex<U> &right)
+{
+  using result_type = typename ProductType<std::complex<T>, U>::type;
+  return static_cast<result_type>(left) / static_cast<result_type>(right);
+}
 #endif /* DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS */
 
 DEAL_II_NAMESPACE_CLOSE

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.