1 #ifndef SimTK_SIMMATRIX_CONJUGATE_H_ 
    2 #define SimTK_SIMMATRIX_CONJUGATE_H_ 
   72 #ifndef SimTK_MIXED_PRECISION_REAL_COMPLEX_ALREADY_DEFINED 
   75 inline complex<float> 
operator*(
const complex<float>& c,
int r) {
return c*(float)r;}
 
   76 inline complex<float> 
operator*(
int r,
const complex<float>& c) {
return (
float)r*c;}
 
   77 inline complex<double> 
operator*(
const complex<float>& c,
const double& r)           {
return complex<double>(c)*r;}
 
   78 inline complex<double> 
operator*(
const double& r,
const complex<float>& c)           {
return r*complex<double>(c);}
 
   80 inline complex<float> 
operator/(
const complex<float>& c,
int r) {
return c/(float)r;}
 
   81 inline complex<float> 
operator/(
int r,
const complex<float>& c) {
return (
float)r/c;}
 
   82 inline complex<double> 
operator/(
const complex<float>& c,
const double& r)           {
return complex<double>(c)/r;}
 
   83 inline complex<double> 
operator/(
const double& r,
const complex<float>& c)           {
return r/complex<double>(c);}
 
   85 inline complex<float> 
operator+(
const complex<float>& c,
int r) {
return c+(float)r;}
 
   86 inline complex<float> 
operator+(
int r,
const complex<float>& c) {
return (
float)r+c;}
 
   87 inline complex<double> 
operator+(
const complex<float>& c,
const double& r)           {
return complex<double>(c)+r;}
 
   88 inline complex<double> 
operator+(
const double& r,
const complex<float>& c)           {
return r+complex<double>(c);}
 
   90 inline complex<float> 
operator-(
const complex<float>& c,
int r) {
return c-(float)r;}
 
   91 inline complex<float> 
operator-(
int r,
const complex<float>& c) {
return (
float)r-c;}
 
   92 inline complex<double> 
operator-(
const complex<float>& c,
const double& r)           {
return complex<double>(c)-r;}
 
   93 inline complex<double> 
operator-(
const double& r,
const complex<float>& c)           {
return r-complex<double>(c);}
 
   96 inline complex<double> 
operator*(
const complex<double>& c,
int r) {
return c*(double)r;}
 
   97 inline complex<double> 
operator*(
int r,
const complex<double>& c) {
return (
double)r*c;}
 
   98 inline complex<double> 
operator*(
const complex<double>& c,
const float& r)           {
return c*(double)r;}
 
   99 inline complex<double> 
operator*(
const float& r,
const complex<double>& c)           {
return (
double)r*c;}
 
  101 inline complex<double> 
operator/(
const complex<double>& c,
int r) {
return c/(double)r;}
 
  102 inline complex<double> 
operator/(
int r,
const complex<double>& c) {
return (
double)r/c;}
 
  103 inline complex<double> 
operator/(
const complex<double>& c,
const float& r)           {
return c/(double)r;}
 
  104 inline complex<double> 
operator/(
const float& r,
const complex<double>& c)           {
return (
double)r/c;}
 
  106 inline complex<double> 
operator+(
const complex<double>& c,
int r) {
return c+(double)r;}
 
  107 inline complex<double> 
operator+(
int r,
const complex<double>& c) {
return (
double)r+c;}
 
  108 inline complex<double> 
operator+(
const complex<double>& c,
const float& r)           {
return c+(double)r;}
 
  109 inline complex<double> 
operator+(
const float& r,
const complex<double>& c)           {
return (
double)r+c;}
 
  111 inline complex<double> 
operator-(
const complex<double>& c,
int r) {
return c-(double)r;}
 
  112 inline complex<double> 
operator-(
int r,
const complex<double>& c) {
return (
double)r-c;}
 
  113 inline complex<double> 
operator-(
const complex<double>& c,
const float& r)           {
return c-(double)r;}
 
  114 inline complex<double> 
operator-(
const float& r,
const complex<double>& c)           {
return (
double)r-c;}
 
  120 template <
class R> 
class conjugate;    
 
  121 template <> 
class conjugate<float>;
 
  122 template <> 
class conjugate<double>;
 
  132 template <
class N> 
class negator;      
 
  139 template <
class R1, 
class R2> 
struct Wider {};
 
  140 template <> 
struct Wider<float,float> {
 
  145 template <> 
struct Wider<float,double> {
 
  150 template <> 
struct Wider<double,float> {
 
  155 template <> 
struct Wider<double,double> {
 
  188         re = negIm = std::numeric_limits<float>::quiet_NaN();
 
  197     conjugate(
int r, 
int i) { re = float(r); negIm = float(i); }
 
  208       { re = float(rd); negIm = 0.f; }
 
  214       { re = x.real(); negIm = -x.imag(); }
 
  216       { re = float(x.real()); negIm = float(-x.imag()); }
 
  220     operator complex<float>()
 const 
  221       { 
return complex<float>(re,-negIm); } 
 
  226     complex<float> 
operator-()
 const { 
return complex<float>(-re,negIm); }
 
  236       { re = r; negIm = 0.f; 
return *
this; }
 
  238       { re += r; 
return *
this; }
 
  240       { re -= r; 
return *
this; }
 
  242       { re *= r; negIm *= r; 
return *
this; }
 
  244       { re /= r; negIm /= r; 
return *
this; }
 
  247       { re += c.re; negIm += c.negIm; 
return *
this; }
 
  249       { re -= c.re; negIm -= c.negIm; 
return *
this; }
 
  252       { re =  c.real(); negIm = -c.imag(); 
return *
this; }
 
  254       { re += c.real(); negIm -= c.imag(); 
return *
this; }
 
  256       { re -= c.real(); negIm += c.imag(); 
return *
this; }
 
  265         const float r=(re*c.re - negIm*c.negIm);
 
  266         negIm=(re*c.negIm + negIm*c.re); re=r; 
return *
this;
 
  269         const float r=(re*t.real() + negIm*t.imag()); 
 
  270         negIm=(negIm*t.real() - re*t.imag()); re=r; 
return *
this;
 
  276         const complex<float> t = 
conj()/d.
conj();
 
  277         re = t.real(); negIm = t.imag(); 
 
  282         re = t.real(); negIm = t.imag(); 
 
  286     const float&               
real()
 const { 
return re; }
 
  292     const complex<float>& 
conj()
 const { 
return reinterpret_cast<const complex<float>&
>(*this); }
 
  293     complex<float>&       
conj()       { 
return reinterpret_cast<complex<float>&
>(*this); }
 
  296     const float& 
negImag()
 const { 
return negIm; }
 
  298     bool         isReal()
  const { 
return negIm==0.f; }
 
  316         re = negIm = std::numeric_limits<double>::quiet_NaN();
 
  325     conjugate(
int r, 
int i) { re = double(r); negIm = double(i); }
 
  334       { re = double(cf.
real()); negIm = double(cf.
negImag()); }
 
  336       { re = double(rf); negIm = 0.; }
 
  342       { re = double(x.real()); negIm = double(-x.imag()); }
 
  344       { re = x.real(); negIm = -x.imag(); }
 
  348     operator complex<double>()
 const 
  349       { 
return complex<double>(re,-negIm); } 
 
  354     complex<double> 
operator-()
 const { 
return complex<double>(-re,negIm); }
 
  364       { re = r; negIm = 0.; 
return *
this; }
 
  366       { re += r; 
return *
this; }
 
  368       { re -= r; 
return *
this; }
 
  370       { re *= r; negIm *= r; 
return *
this; }
 
  372       { re /= r; negIm /= r; 
return *
this; }
 
  375       { re = r; negIm = 0.; 
return *
this; }
 
  377       { re += r; 
return *
this; }
 
  379       { re -= r; 
return *
this; }
 
  381       { re *= r; negIm *= r; 
return *
this; }
 
  383       { re /= r; negIm /= r; 
return *
this; }
 
  386     conjugate& operator =(
int i) {*
this =(double)i; 
return *
this;}
 
  393       { re += c.re; negIm += c.negIm; 
return *
this; }
 
  395       { re -= c.re; negIm -= c.negIm; 
return *
this; }
 
  398       { re += c.
real(); negIm += c.
negImag(); 
return *
this; }
 
  400       { re -= c.
real(); negIm -= c.
negImag(); 
return *
this; }
 
  403       { re =  c.real(); negIm = -c.imag(); 
return *
this; }
 
  405       { re += c.real(); negIm -= c.imag(); 
return *
this; }
 
  407       { re -= c.real(); negIm += c.imag(); 
return *
this; }
 
  410       { re =  c.real(); negIm = -c.imag(); 
return *
this; }
 
  412       { re += c.real(); negIm -= c.imag(); 
return *
this; }
 
  414       { re -= c.real(); negIm += c.imag(); 
return *
this; }
 
  423         const double r=(re*c.re - negIm*c.negIm);
 
  424         negIm=(re*c.negIm + negIm*c.re); re=r; 
return *
this;
 
  427         const double r=(re*t.real() + negIm*t.imag()); 
 
  428         negIm=(negIm*t.real() - re*t.imag()); re=r; 
return *
this;
 
  437         const complex<double> t = 
conj()/d.
conj();
 
  438         re = t.real(); negIm = t.imag(); 
 
  443         re = t.real(); negIm = t.imag(); 
 
  450     const double&               
real()
 const { 
return re; }
 
  456     const complex<double>& 
conj()
 const { 
return reinterpret_cast<const complex<double>&
>(*this); }
 
  457     complex<double>&       
conj()       { 
return reinterpret_cast<complex<double>&
>(*this); }
 
  460     const double& 
negImag()
 const { 
return negIm; }
 
  462     bool          isReal()
  const { 
return negIm==0.; }
 
  473     re = float(cd.
real()); negIm = float(cd.
negImag());
 
  504 template <
class R, 
class CHAR, 
class TRAITS> 
inline std::basic_istream<CHAR,TRAITS>&
 
  506     complex<R> z; is >> z; c=z;
 
  509 template <
class R, 
class CHAR, 
class TRAITS> 
inline std::basic_ostream<CHAR,TRAITS>&
 
  510 operator<<(std::basic_ostream<CHAR,TRAITS>& os, 
const conjugate<R>& c) {
 
  511     return os << complex<R>(c);
 
  547   { 
return a.isReal() && a.real()==b; }
 
  549   { 
return a.isReal() && a.real()==b; }
 
  570   { 
return complex<R>(a-b.real(), -b.imag()); }
 
  584   { 
return (R)a/complex<R>(b); }
 
  596 template <
class R, 
class S> 
inline typename Wider<R,S>::WConj
 
  599                                       a.negImag()+r.negImag());
 
  603 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  606                                       r.imag()-a.negImag());
 
  608 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  612 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  615                                       r.negImag()-a.negImag());
 
  619 template <
class R, 
class S> 
inline negator<typename Wider<R,S>::WCplx>
 
  623                                          a.negImag()+r.imag()));
 
  627 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  630                                       a.imag()+r.negImag());
 
  639 template <
class R, 
class S> 
inline negator<typename Wider<R,S>::WCplx>
 
  643                                        a.real()*r.negImag()    + a.negImag()*r.real()));
 
  647 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  650                                       a.real()*r.imag() - a.negImag()*r.real());
 
  653 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  660 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  662   { 
return (-a)*(-r); } 
 
  663 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  665   { 
return (-a)*(-r); } 
 
  671 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  676 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  681 template <
class R, 
class S> 
inline typename Wider<R,S>::WCplx
 
  687 template <
class R, 
class S> 
inline bool 
  689     return a.real() == r.real() && a.negImag() == r.negImag();
 
  692 template <
class R, 
class S> 
inline bool 
  694     return a.real() == r.real() && -a.negImag() == r.imag();
 
  697 template <
class R, 
class S> 
inline bool 
  700 template <
class R, 
class S> 
inline bool 
  703 template <
class R, 
class S> 
inline bool 
  706 template <
class R, 
class S> 
inline bool 
Definition: conjugate.h:312
 
double & negImag()
Definition: conjugate.h:461
 
conjugate & operator*=(const complex< double > &t)
Definition: conjugate.h:426
 
conjugate & operator=(const double &r)
Definition: conjugate.h:363
 
complex< double > & conj()
Definition: conjugate.h:457
 
conjugate(int r, const double &imag)
Definition: conjugate.h:324
 
conjugate(int r, int i)
Definition: conjugate.h:325
 
conjugate & operator/=(const double &r)
Definition: conjugate.h:371
 
conjugate & operator/=(int i)
Definition: conjugate.h:390
 
double & real()
Definition: conjugate.h:451
 
conjugate & operator*=(const conjugate< float > &c)
Definition: conjugate.h:431
 
conjugate(const complex< float > &x)
Definition: conjugate.h:341
 
conjugate & operator+=(const float &r)
Definition: conjugate.h:376
 
conjugate & operator-=(const complex< double > &c)
Definition: conjugate.h:406
 
const double & negImag() const
Definition: conjugate.h:460
 
conjugate & operator/=(const complex< float > &c)
Definition: conjugate.h:448
 
conjugate & operator-=(const double &r)
Definition: conjugate.h:367
 
conjugate & operator+=(const double &r)
Definition: conjugate.h:365
 
const conjugate & operator+() const
Definition: conjugate.h:357
 
conjugate & operator=(const float &r)
Definition: conjugate.h:374
 
conjugate & operator-=(const conjugate< float > &c)
Definition: conjugate.h:399
 
conjugate & operator=(const complex< double > &c)
Definition: conjugate.h:402
 
conjugate & operator+=(const conjugate< double > &c)
Definition: conjugate.h:392
 
conjugate(const complex< double > &x)
Definition: conjugate.h:343
 
conjugate & operator+=(const conjugate< float > &c)
Definition: conjugate.h:397
 
conjugate & operator*=(const float &r)
Definition: conjugate.h:380
 
conjugate & operator-=(int i)
Definition: conjugate.h:388
 
conjugate(const double &real, const double &imag)
Construction from reals. Note that the numeric result is (real-imag*i).
Definition: conjugate.h:322
 
conjugate & operator=(const complex< float > &c)
Definition: conjugate.h:409
 
conjugate & operator*=(int i)
Definition: conjugate.h:389
 
negator< double > & imag()
Definition: conjugate.h:454
 
bool isReal() const
Definition: conjugate.h:462
 
conjugate & operator*=(const conjugate< double > &c)
Definition: conjugate.h:422
 
conjugate & operator/=(const complex< double > &d)
Definition: conjugate.h:441
 
conjugate & operator/=(const conjugate< float > &c)
Definition: conjugate.h:447
 
conjugate & operator-=(const float &r)
Definition: conjugate.h:378
 
conjugate & operator*=(const complex< float > &c)
Definition: conjugate.h:432
 
conjugate(const double &real, int i)
Definition: conjugate.h:323
 
conjugate & operator/=(const conjugate< double > &d)
Definition: conjugate.h:436
 
const negator< double > & imag() const
Definition: conjugate.h:453
 
const double & real() const
Definition: conjugate.h:450
 
conjugate & operator/=(const float &r)
Definition: conjugate.h:382
 
conjugate & operator+=(int i)
Definition: conjugate.h:387
 
conjugate & operator+=(const complex< float > &c)
Definition: conjugate.h:411
 
conjugate(int r)
Definition: conjugate.h:329
 
const complex< double > & conj() const
Definition: conjugate.h:456
 
complex< double > operator-() const
Definition: conjugate.h:354
 
conjugate()
Definition: conjugate.h:314
 
conjugate & operator*=(const double &r)
Definition: conjugate.h:369
 
conjugate & operator-=(const conjugate< double > &c)
Definition: conjugate.h:394
 
conjugate & operator-=(const complex< float > &c)
Definition: conjugate.h:413
 
conjugate & operator+=(const complex< double > &c)
Definition: conjugate.h:404
 
conjugate(const double &real)
Implicit conversion from double to conjugate<double>.
Definition: conjugate.h:328
 
conjugate(const conjugate< float > &cf)
Definition: conjugate.h:333
 
conjugate(const float &rf)
Definition: conjugate.h:335
 
Definition: conjugate.h:184
 
conjugate & operator-=(const conjugate< float > &c)
Definition: conjugate.h:248
 
conjugate & operator/=(const complex< float > &d)
Definition: conjugate.h:280
 
conjugate(int r, int i)
Definition: conjugate.h:197
 
conjugate(const float &real, int i)
Definition: conjugate.h:195
 
conjugate & operator/=(const conjugate< float > &d)
Definition: conjugate.h:275
 
conjugate(const float &real, const float &imag)
Construction from reals. Note that the numeric result is (real-imag*i).
Definition: conjugate.h:194
 
conjugate & operator=(const complex< float > &c)
Definition: conjugate.h:251
 
complex< float > & conj()
Definition: conjugate.h:293
 
conjugate(int r, const float &imag)
Definition: conjugate.h:196
 
conjugate & operator+=(const float &r)
Definition: conjugate.h:237
 
conjugate(int r)
Definition: conjugate.h:201
 
conjugate & operator-=(const float &r)
Definition: conjugate.h:239
 
conjugate & operator+=(const conjugate< float > &c)
Definition: conjugate.h:246
 
conjugate & operator*=(const float &r)
Definition: conjugate.h:241
 
float & real()
Definition: conjugate.h:287
 
const negator< float > & imag() const
Definition: conjugate.h:289
 
conjugate(const complex< double > &x)
Definition: conjugate.h:215
 
negator< float > & imag()
Definition: conjugate.h:290
 
conjugate & operator+=(const complex< float > &c)
Definition: conjugate.h:253
 
bool isReal() const
Definition: conjugate.h:298
 
const float & negImag() const
Definition: conjugate.h:296
 
const conjugate & operator+() const
Definition: conjugate.h:229
 
conjugate(const double &rd)
Definition: conjugate.h:207
 
conjugate(const float &real)
Implicit conversion from float to conjugate<float>.
Definition: conjugate.h:200
 
const float & real() const
Definition: conjugate.h:286
 
conjugate & operator=(const float &r)
Definition: conjugate.h:235
 
float & negImag()
Definition: conjugate.h:297
 
conjugate & operator*=(const conjugate< float > &c)
Definition: conjugate.h:264
 
complex< float > operator-() const
Definition: conjugate.h:226
 
conjugate(const complex< float > &x)
Definition: conjugate.h:213
 
conjugate & operator/=(const float &r)
Definition: conjugate.h:243
 
const complex< float > & conj() const
Definition: conjugate.h:292
 
conjugate & operator*=(const complex< float > &t)
Definition: conjugate.h:268
 
conjugate()
Definition: conjugate.h:186
 
conjugate & operator-=(const complex< float > &c)
Definition: conjugate.h:255
 
SimTK::conjugate<R> should be instantiated only for float, double.
Definition: conjugate.h:178
 
negator<N>, where N is a number type (real, complex, conjugate), is represented in memory identically...
Definition: negator.h:75
 
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
 
Matrix_< typename CNT< E1 >::template Result< E2 >::Sub > operator-(const MatrixBase< E1 > &l, const MatrixBase< E2 > &r)
Definition: BigMatrix.h:584
 
Matrix_< E > operator/(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition: BigMatrix.h:613
 
std::ostream & operator<<(std::ostream &o, const ContactForce &f)
Definition: CompliantContactSubsystem.h:387
 
std::basic_istream< CHAR, TRAITS > & operator>>(std::basic_istream< CHAR, TRAITS > &is, conjugate< R > &c)
Definition: conjugate.h:505
 
const complex< double > & conj(const conjugate< double > &c)
Definition: conjugate.h:490
 
Matrix_< typename CNT< E1 >::template Result< E2 >::Add > operator+(const MatrixBase< E1 > &l, const MatrixBase< E2 > &r)
Definition: BigMatrix.h:568
 
double norm(const conjugate< double > &c)
Definition: conjugate.h:492
 
RowVectorBase< typename CNT< ELEM >::TAbs > abs(const RowVectorBase< ELEM > &v)
Definition: VectorMath.h:120
 
const complex< float > & conj(const conjugate< float > &c)
Definition: conjugate.h:484
 
float norm(const conjugate< float > &c)
Definition: conjugate.h:486
 
const negator< float > & imag(const conjugate< float > &c)
Definition: conjugate.h:483
 
Matrix_< E > operator*(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition: BigMatrix.h:605
 
bool operator==(const PhiMatrix &p1, const PhiMatrix &p2)
Definition: SpatialAlgebra.h:791
 
bool operator!=(const L &left, const R &right)
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:645
 
const float & real(const conjugate< float > &c)
Definition: conjugate.h:482
 
double abs(const conjugate< double > &c)
Definition: conjugate.h:491
 
double WReal
Definition: conjugate.h:156
 
complex< double > WCplx
Definition: conjugate.h:157
 
conjugate< double > WConj
Definition: conjugate.h:158
 
conjugate< double > WConj
Definition: conjugate.h:153
 
double WReal
Definition: conjugate.h:151
 
complex< double > WCplx
Definition: conjugate.h:152
 
double WReal
Definition: conjugate.h:146
 
conjugate< double > WConj
Definition: conjugate.h:148
 
complex< double > WCplx
Definition: conjugate.h:147
 
complex< float > WCplx
Definition: conjugate.h:142
 
float WReal
Definition: conjugate.h:141
 
conjugate< float > WConj
Definition: conjugate.h:143
 
Definition: conjugate.h:139