@@ -36,25 +36,13 @@ class bigcomplex{
3636 RR imag () const {return im;};
3737 RR norm () const {return sqr (re)+sqr (im);};
3838 RR arg () const { return atan2 (im, re);};
39- RR abs2 () const {return sqr (re)+sqr (im);};
40- RR abs () const {return ::NTL::sqrt (abs2 ());};
39+ RR abs () const {return ::NTL::sqrt (norm ());};
4140 bigcomplex conj () const {return bigcomplex (re,-im);};
4241 bigcomplex timesI () const {return bigcomplex (-im,re);};
4342 int IsReal () const {return ::NTL::IsZero (im);}
4443 int IsImaginary () const {return ::NTL::IsZero (re);}
4544 int IsZero () const {return ::NTL::IsZero (re) && ::NTL::IsZero (im);}
4645
47- // same again, as functions
48- friend RR real (const bigcomplex& z) {return z.re ;};
49- friend RR imag (const bigcomplex& z) {return z.im ;};
50- friend RR norm (const bigcomplex& z) {return sqr (z.re )+sqr (z.im );};
51- friend RR arg (const bigcomplex& z) { return atan2 (z.im , z.re );};
52- friend RR abs2 (const bigcomplex& z) {return sqr (z.re )+sqr (z.im );};
53- friend RR abs (const bigcomplex& z) {return ::NTL::sqrt (z.abs2 ());};
54- friend bigcomplex conj (const bigcomplex& z) {return bigcomplex (z.re ,-z.im );};
55- int IsReal (const bigcomplex& z) {return z.IsReal ();}
56- int IsImaginary (const bigcomplex& z) {return z.IsImaginary ();}
57- int IsZero (const bigcomplex& z) {return z.IsZero ();}
5846
5947 bigcomplex operator = (const RR& r) {re=r; im=RR (); return *this ;}
6048 bigcomplex operator +=(const RR& r) {re+=r; return *this ;};
@@ -68,37 +56,32 @@ class bigcomplex{
6856
6957 bigcomplex operator =(const bigcomplex& z) {re=z.re ; im=z.im ; return *this ;};
7058 bigcomplex operator +=(const bigcomplex& z) {re+=z.re ; im+=z.im ; return *this ;};
71- bigcomplex operator +(const bigcomplex& z) const {bigcomplex w (* this ); w+=z; return w ;};
59+ bigcomplex operator +(const bigcomplex& z) const {return bigcomplex (re+z. re , im+z. im ) ;};
7260 bigcomplex operator +() {return *this ;};
7361 bigcomplex operator -=(const bigcomplex& z) {re-=z.re ; im-=z.im ; return *this ;};
74- bigcomplex operator -(const bigcomplex& z) const {bigcomplex w (* this ); w-=z; return w ;};
62+ bigcomplex operator -(const bigcomplex& z) const {return bigcomplex (re-z. re , im-z. im ) ;};
7563 bigcomplex operator -() const {return bigcomplex (-re,-im);};
76- bigcomplex operator *=(const bigcomplex& z) {RR x = re; re=x*z.re -im*z.re ; im = x*z.im +im*z.re ; return *this ;};
64+ bigcomplex operator *=(const bigcomplex& z) {RR x = re; re=x*z.re -im*z.im ; im = x*z.im +im*z.re ; return *this ;};
7765 bigcomplex operator *(const bigcomplex& z) const {bigcomplex w (*this ); w*=z; return w;};
78- bigcomplex operator /=(const bigcomplex& z) {RR r=z.abs2 (), x = re; re=(x*z.re +im*z.re )/r; im = (-x*z.im +im*z.re )/r; return *this ;};
66+ bigcomplex operator /=(const bigcomplex& z) {RR r=z.norm (), x = re; re=(x*z.re +im*z.im )/r; im = (-x*z.im +im*z.re )/r; return *this ;};
7967 bigcomplex operator /(const bigcomplex& z) const {bigcomplex w (*this ); w/=z; return w;};
8068
81- // operators with left operand RR
82- friend bigcomplex operator +(const RR& r, const bigcomplex& z) {return bigcomplex (r)+z;};
83- friend bigcomplex operator -(const RR& r, const bigcomplex& z) {return bigcomplex (r)-z;};
84- friend bigcomplex operator *(const RR& r, const bigcomplex& z) {return bigcomplex (r)*z;};
85- friend bigcomplex operator /(const RR& r, const bigcomplex& z) {return bigcomplex (r)/z;};
86-
8769 // standard functions as class methods:
8870 bigcomplex sqrt () const {RR r = abs (); RR u = ::NTL::sqrt ((r+re)/2 ), v=::NTL::sqrt ((r-re)/2 ); if (im<0 ) v=-v; return bigcomplex (u,v);};
8971 bigcomplex cos () const {bigcomplex z (this ->timesI ()); return (z+z.conj ())/to_RR (2 );};
9072 bigcomplex sin () const {bigcomplex z (this ->timesI ()); return (z-z.conj ())/bigcomplex (RR (),to_RR (2 ));};
9173 bigcomplex exp () const {RR e = ::NTL::exp (re); return bigcomplex (e * ::NTL::cos (im), e * ::NTL::sin (im));};
9274 bigcomplex log () const {return bigcomplex (::NTL::log (abs ()), arg ());}
9375
94- // standard functions as functions:
95- friend bigcomplex sqrt (const bigcomplex& z) {bigcomplex w (z); return w.sqrt ();};
96- friend bigcomplex cos (const bigcomplex& z) {bigcomplex w (z); return w.cos ();};
97- friend bigcomplex sin (const bigcomplex& z) {bigcomplex w (z); return w.sin ();};
98- friend bigcomplex exp (const bigcomplex& z) {bigcomplex w (z); return w.exp ();};
99- friend bigcomplex log (const bigcomplex& z) {bigcomplex w (z); return w.log ();};
10076
10177 operator string () const
78+ {
79+ ostringstream s;
80+ s << " (" << re << " ," << im << " )" ;
81+ return s.str ();
82+ }
83+
84+ string pretty_string () const
10285 {
10386 ostringstream s;
10487 if (IsReal ())
@@ -132,7 +115,7 @@ class bigcomplex{
132115
133116 friend ostream& operator <<(ostream& s, const bigcomplex& z)
134117 {
135- s << ( string)z ;
118+ s << string (z) ;
136119 return s;
137120 }
138121
@@ -141,9 +124,32 @@ class bigcomplex{
141124 RR re, im;
142125};
143126
144- inline void swap (bigcomplex& z1, bigcomplex& z2)
145- {
146- bigcomplex z3 (z1); z1=z2; z2=z3;
147- }
127+
128+ // inline functions
129+ inline RR real (const bigcomplex& z) {return z.real ();};
130+ inline RR imag (const bigcomplex& z) {return z.imag ();};
131+ inline RR norm (const bigcomplex& z) {return z.norm ();};
132+ inline RR arg (const bigcomplex& z) { return z.arg ();};
133+ inline RR abs (const bigcomplex& z) {return z.abs ();};
134+ inline bigcomplex conj (const bigcomplex& z) {return z.conj ();};
135+ inline int IsReal (const bigcomplex& z) {return z.IsReal ();}
136+ inline int IsImaginary (const bigcomplex& z) {return z.IsImaginary ();}
137+ inline int IsZero (const bigcomplex& z) {return z.IsZero ();}
138+
139+ // operators with left operand RR
140+ inline bigcomplex operator +(const RR& r, const bigcomplex& z) {return bigcomplex (r)+z;};
141+ inline bigcomplex operator -(const RR& r, const bigcomplex& z) {return bigcomplex (r)-z;};
142+ inline bigcomplex operator *(const RR& r, const bigcomplex& z) {return bigcomplex (r)*z;};
143+ inline bigcomplex operator /(const RR& r, const bigcomplex& z) {return bigcomplex (r)/z;};
144+
145+ // standard method functions as functions:
146+ inline bigcomplex sqrt (const bigcomplex& z) {bigcomplex w (z); return w.sqrt ();};
147+ inline bigcomplex cos (const bigcomplex& z) {bigcomplex w (z); return w.cos ();};
148+ inline bigcomplex sin (const bigcomplex& z) {bigcomplex w (z); return w.sin ();};
149+ inline bigcomplex exp (const bigcomplex& z) {bigcomplex w (z); return w.exp ();};
150+ inline bigcomplex log (const bigcomplex& z) {bigcomplex w (z); return w.log ();};
151+
152+
153+ inline void swap (bigcomplex& z1, bigcomplex& z2) {bigcomplex z3 (z1); z1=z2; z2=z3;}
148154
149155#endif
0 commit comments