This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi,  ÂComplex number multiplication done with 4 multiplications, but this one only need 3:       (a+ib)(c+id) = ac - bd + i( bc + ad ) -- 4 multiplies                Â= ac - bd + i[ ( a + b )( c + d ) - ac - bd ] -- 3 multiplies diff -ru gcc/libstdc++-v3/include/std/complex gcc.working.copy/libstdc++-v3//include/std/complex --- gcc/libstdc++-v3/include/std/complex    Â2010-08-13 16:48:07.000000000 +0800 +++ gcc.working.copy/libstdc++-v3//include/std/complex Â2010-09-11 13:21:00.000000000 +0800 @@ -291,9 +291,13 @@   complex<_Tp>&   complex<_Tp>::operator*=(const complex<_Up>& __z)   { -   Âconst _Tp __r = _M_real * __z.real() - _M_imag * __z.imag(); -   Â_M_imag = _M_real * __z.imag() + _M_imag * __z.real(); -   Â_M_real = __r; +   Â//(a+ib)(c+id) = ac - bd + i( bc + ad ) -- 4 multiplies +   Â//       = ac - bd + i[ ( a + b )( c + d ) - ac - bd ] -- 3 multiplies +   Âconst _Tp ac = _M_real * __z.real(); +   Âconst _Tp bd = _M_imag * __z.imag(); +   Âconst _Tp ab_cd = (_M_real+_M_imag) * (__z.real()+__z.imag()); +   Â_M_real = ac - bd; +   Â_M_imag = ab_cd - ac - bd;    return *this;   } @@ -304,10 +308,11 @@   complex<_Tp>&   complex<_Tp>::operator/=(const complex<_Up>& __z)   { -   Âconst _Tp __r = Â_M_real * __z.real() + _M_imag * __z.imag(); -   Âconst _Tp __n = std::norm(__z); -   Â_M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n; -   Â_M_real = __r / __n; +   Â// a + ib  Â( a + ib ) ( c - id ) +   Â//-------- = --------------------- Â-- 6 multiplies +   Â// c + id     Âc^2 + d^2 +   Â*this *= conj(__z); +   Â*this /= norm(__z);    return *this;   }
Attachment:
complex.patch
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |