Skip to content

Commit

Permalink
Math: "dot product" of Complex is real number.
Browse files Browse the repository at this point in the history
Brain failure #2. Also I don't know if such thing as dot product exists
here :-)
  • Loading branch information
mosra committed Feb 27, 2013
1 parent 1eea843 commit c847e15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/Math/Complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ template<class T> class Complex {
* @brief Dot product
*
* @f[
* c_0 \cdot c_1 = c_0 \overline{c_1} = (a_0 a_1 + b_0 b_1) + i(a_1 b_0 - a_0 b_1)
* c_0 \cdot c_1 = a_0 a_1 + b_0 b_1
* @f]
* @see dot() const
*/
inline static Complex<T> dot(const Complex<T>& a, const Complex<T>& b) {
return a*b.conjugated();
inline static T dot(const Complex<T>& a, const Complex<T>& b) {
return a._real*b._real + a._imaginary*b._imaginary;
}

/**
Expand Down Expand Up @@ -277,20 +277,20 @@ template<class T> class Complex {
*
* Should be used instead of length() for comparing complex number length
* with other values, because it doesn't compute the square root. @f[
* c \cdot c = c \overline c = a^2 + b^2
* c \cdot c = a^2 + b^2
* @f]
* @see dot(const Complex&, const Complex&)
*/
inline T dot() const {
return _real*_real + _imaginary*_imaginary;
return dot(*this, *this);
}

/**
* @brief %Complex number length
*
* See also dot() const which is faster for comparing length with other
* values. @f[
* |c| = \sqrt{c \overline c} = \sqrt{a^2 + b^2}
* |c| = \sqrt{c \cdot c}
* @f]
*/
inline T length() const {
Expand Down Expand Up @@ -318,7 +318,7 @@ template<class T> class Complex {
*
* See invertedNormalized() which is faster for normalized
* complex numbers. @f[
* c^{-1} = \frac{\overline c}{c \overline c} = \frac{\overline c}{a^2 + b^2}
* c^{-1} = \frac{\overline c}{|c|^2} = \frac{\overline c}{c \cdot c}
* @f]
*/
inline Complex<T> inverted() const {
Expand Down
2 changes: 1 addition & 1 deletion src/Math/Test/ComplexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void ComplexTest::dot() {
Complex a(5.0f, 3.0f);
Complex b(6.0f, -7.0f);

CORRADE_COMPARE(Complex::dot(a, b), Complex(9.0f, 53.0f));
CORRADE_COMPARE(Complex::dot(a, b), 9.0f);
}

void ComplexTest::dotSelf() {
Expand Down

0 comments on commit c847e15

Please sign in to comment.