Public Member Functions | Private Attributes | Friends
gmp_complex Class Reference

gmp_complex numbers based on More...

#include <mpr_complex.h>

Public Member Functions

 gmp_complex (const gmp_float re=0.0, const gmp_float im=0.0)
 
 gmp_complex (const mprfloat re, const mprfloat im=0.0)
 
 gmp_complex (const long re, const long im)
 
 gmp_complex (const gmp_complex &v)
 
 ~gmp_complex ()
 
gmp_complexneg ()
 
gmp_complexoperator+= (const gmp_complex &a)
 
gmp_complexoperator-= (const gmp_complex &a)
 
gmp_complexoperator*= (const gmp_complex &a)
 
gmp_complexoperator/= (const gmp_complex &a)
 
gmp_complexoperator= (const gmp_complex &a)
 
gmp_complexoperator= (const gmp_float &f)
 
gmp_float real () const
 
gmp_float imag () const
 
void real (gmp_float val)
 
void imag (gmp_float val)
 
bool isZero ()
 
void SmallToZero ()
 

Private Attributes

gmp_float r
 
gmp_float i
 

Friends

gmp_complex operator+ (const gmp_complex &a, const gmp_complex &b)
 
gmp_complex operator- (const gmp_complex &a, const gmp_complex &b)
 
gmp_complex operator* (const gmp_complex &a, const gmp_complex &b)
 
gmp_complex operator/ (const gmp_complex &a, const gmp_complex &b)
 
gmp_complex operator+ (const gmp_complex &a, const gmp_float b_d)
 
gmp_complex operator- (const gmp_complex &a, const gmp_float b_d)
 
gmp_complex operator* (const gmp_complex &a, const gmp_float b_d)
 
gmp_complex operator/ (const gmp_complex &a, const gmp_float b_d)
 
bool operator== (const gmp_complex &a, const gmp_complex &b)
 
bool operator> (const gmp_complex &a, const gmp_complex &b)
 
bool operator< (const gmp_complex &a, const gmp_complex &b)
 
bool operator>= (const gmp_complex &a, const gmp_complex &b)
 
bool operator<= (const gmp_complex &a, const gmp_complex &b)
 

Detailed Description

gmp_complex numbers based on

Definition at line 178 of file mpr_complex.h.

Constructor & Destructor Documentation

◆ gmp_complex() [1/4]

gmp_complex::gmp_complex ( const gmp_float  re = 0.0,
const gmp_float  im = 0.0 
)
inline

Definition at line 184 of file mpr_complex.h.

185  {
186  r= re;
187  i= im;
188  }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181

◆ gmp_complex() [2/4]

gmp_complex::gmp_complex ( const mprfloat  re,
const mprfloat  im = 0.0 
)
inline

Definition at line 189 of file mpr_complex.h.

190  {
191  r= re;
192  i= im;
193  }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181

◆ gmp_complex() [3/4]

gmp_complex::gmp_complex ( const long  re,
const long  im 
)
inline

Definition at line 194 of file mpr_complex.h.

195  {
196  r= re;
197  i= im;
198  }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181

◆ gmp_complex() [4/4]

gmp_complex::gmp_complex ( const gmp_complex v)
inline

Definition at line 199 of file mpr_complex.h.

200  {
201  r= v.r;
202  i= v.i;
203  }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181

◆ ~gmp_complex()

gmp_complex::~gmp_complex ( )
inline

Definition at line 204 of file mpr_complex.h.

204 {}

Member Function Documentation

◆ imag() [1/2]

gmp_float gmp_complex::imag ( ) const
inline

Definition at line 235 of file mpr_complex.h.

235 { return i; }
gmp_float i
Definition: mpr_complex.h:181

◆ imag() [2/2]

void gmp_complex::imag ( gmp_float  val)
inline

Definition at line 238 of file mpr_complex.h.

238 { i = val; }
gmp_float i
Definition: mpr_complex.h:181

◆ isZero()

bool gmp_complex::isZero ( )
inline

Definition at line 241 of file mpr_complex.h.

241 { return (r.isZero() && i.isZero()); }
gmp_float i
Definition: mpr_complex.h:181
bool isZero() const
Definition: mpr_complex.cc:253
gmp_float r
Definition: mpr_complex.h:181

◆ neg()

gmp_complex & gmp_complex::neg ( )

Definition at line 661 of file mpr_complex.cc.

662 {
663  i.neg();
664  r.neg();
665  return *this;
666 }
gmp_float & neg()
Definition: mpr_complex.h:100
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181

◆ operator*=()

gmp_complex & gmp_complex::operator*= ( const gmp_complex a)

Definition at line 654 of file mpr_complex.cc.

655 {
656  gmp_float f = r * b.r - i * b.i;
657  i = r * b.i + i * b.r;
658  r = f;
659  return *this;
660 }
gmp_float i
Definition: mpr_complex.h:181
CanonicalForm b
Definition: cfModGcd.cc:4044
gmp_float r
Definition: mpr_complex.h:181
FILE * f
Definition: checklibs.c:9

◆ operator+=()

gmp_complex & gmp_complex::operator+= ( const gmp_complex a)

Definition at line 642 of file mpr_complex.cc.

643 {
644  r+=b.r;
645  i+=b.i;
646  return *this;
647 }
gmp_float i
Definition: mpr_complex.h:181
CanonicalForm b
Definition: cfModGcd.cc:4044
gmp_float r
Definition: mpr_complex.h:181

◆ operator-=()

gmp_complex & gmp_complex::operator-= ( const gmp_complex a)

Definition at line 648 of file mpr_complex.cc.

649 {
650  r-=b.r;
651  i-=b.i;
652  return *this;
653 }
gmp_float i
Definition: mpr_complex.h:181
CanonicalForm b
Definition: cfModGcd.cc:4044
gmp_float r
Definition: mpr_complex.h:181

◆ operator/=()

gmp_complex & gmp_complex::operator/= ( const gmp_complex a)

Definition at line 667 of file mpr_complex.cc.

668 {
669  gmp_float d = b.r*b.r + b.i*b.i;
670  r = (r * b.r + i * b.i) / d;
671  i = (i * b.r - r * b.i) / d;
672  return *this;
673 }
gmp_float i
Definition: mpr_complex.h:181
CanonicalForm b
Definition: cfModGcd.cc:4044
gmp_float r
Definition: mpr_complex.h:181

◆ operator=() [1/2]

gmp_complex & gmp_complex::operator= ( const gmp_complex a)
inline

Definition at line 288 of file mpr_complex.h.

289 {
290  r= a.r;
291  i= a.i;
292  return *this;
293 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181

◆ operator=() [2/2]

gmp_complex & gmp_complex::operator= ( const gmp_float f)
inline

Definition at line 296 of file mpr_complex.h.

297 {
298  r= f;
299  i= (long int)0;
300  return *this;
301 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
FILE * f
Definition: checklibs.c:9

◆ real() [1/2]

gmp_float gmp_complex::real ( ) const
inline

Definition at line 234 of file mpr_complex.h.

234 { return r; }
gmp_float r
Definition: mpr_complex.h:181

◆ real() [2/2]

void gmp_complex::real ( gmp_float  val)
inline

Definition at line 237 of file mpr_complex.h.

237 { r = val; }
gmp_float r
Definition: mpr_complex.h:181

◆ SmallToZero()

void gmp_complex::SmallToZero ( )

Definition at line 785 of file mpr_complex.cc.

786 {
787  gmp_float ar=this->real();
788  gmp_float ai=this->imag();
789  if (ar.isZero() || ai.isZero()) return;
790  mpf_abs(*ar._mpfp(), *ar._mpfp());
791  mpf_abs(*ai._mpfp(), *ai._mpfp());
792  mpf_set_prec(*ar._mpfp(), 32);
793  mpf_set_prec(*ai._mpfp(), 32);
794  if (ar > ai)
795  {
796  mpf_div(*ai._mpfp(), *ai._mpfp(), *ar._mpfp());
797  if (ai < *gmpRel) this->imag(0.0);
798  }
799  else
800  {
801  mpf_div(*ar._mpfp(), *ar._mpfp(), *ai._mpfp());
802  if (ar < *gmpRel) this->real(0.0);
803  }
804 }
mpf_t * _mpfp()
Definition: mpr_complex.h:134
gmp_float real() const
Definition: mpr_complex.h:234
bool isZero() const
Definition: mpr_complex.cc:253
static gmp_float * gmpRel
Definition: mpr_complex.cc:45
gmp_float imag() const
Definition: mpr_complex.h:235

Friends And Related Function Documentation

◆ operator* [1/2]

gmp_complex operator* ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 628 of file mpr_complex.cc.

629 {
630  return gmp_complex( a.r * b.r - a.i * b.i,
631  a.r * b.i + a.i * b.r);
632 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition: mpr_complex.h:184

◆ operator* [2/2]

gmp_complex operator* ( const gmp_complex a,
const gmp_float  b_d 
)
friend

Definition at line 255 of file mpr_complex.h.

256 {
257  return gmp_complex( a.r * b_d, a.i * b_d );
258 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition: mpr_complex.h:184

◆ operator+ [1/2]

gmp_complex operator+ ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 620 of file mpr_complex.cc.

621 {
622  return gmp_complex( a.r + b.r, a.i + b.i );
623 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition: mpr_complex.h:184

◆ operator+ [2/2]

gmp_complex operator+ ( const gmp_complex a,
const gmp_float  b_d 
)
friend

Definition at line 247 of file mpr_complex.h.

248 {
249  return gmp_complex( a.r + b_d, a.i );
250 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition: mpr_complex.h:184

◆ operator- [1/2]

gmp_complex operator- ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 624 of file mpr_complex.cc.

625 {
626  return gmp_complex( a.r - b.r, a.i - b.i );
627 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition: mpr_complex.h:184

◆ operator- [2/2]

gmp_complex operator- ( const gmp_complex a,
const gmp_float  b_d 
)
friend

Definition at line 251 of file mpr_complex.h.

252 {
253  return gmp_complex( a.r - b_d, a.i );
254 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition: mpr_complex.h:184

◆ operator/ [1/2]

gmp_complex operator/ ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 633 of file mpr_complex.cc.

634 {
635  gmp_float d = b.r*b.r + b.i*b.i;
636  return gmp_complex( (a.r * b.r + a.i * b.i) / d,
637  (a.i * b.r - a.r * b.i) / d);
638 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition: mpr_complex.h:184

◆ operator/ [2/2]

gmp_complex operator/ ( const gmp_complex a,
const gmp_float  b_d 
)
friend

Definition at line 259 of file mpr_complex.h.

260 {
261  return gmp_complex( a.r / b_d, a.i / b_d );
262 }
gmp_float i
Definition: mpr_complex.h:181
gmp_float r
Definition: mpr_complex.h:181
gmp_complex(const gmp_float re=0.0, const gmp_float im=0.0)
Definition: mpr_complex.h:184

◆ operator<

bool operator< ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 273 of file mpr_complex.h.

274 {
275  return ( a.real() < b.real() );
276 }
gmp_float real() const
Definition: mpr_complex.h:234

◆ operator<=

bool operator<= ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 281 of file mpr_complex.h.

282 {
283  return ( a.real() <= b.real() );
284 }
gmp_float real() const
Definition: mpr_complex.h:234

◆ operator==

bool operator== ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 265 of file mpr_complex.h.

266 {
267  return ( b.real() == a.real() ) && ( b.imag() == a.imag() );
268 }
gmp_float real() const
Definition: mpr_complex.h:234
gmp_float imag() const
Definition: mpr_complex.h:235

◆ operator>

bool operator> ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 269 of file mpr_complex.h.

270 {
271  return ( a.real() > b.real() );
272 }
gmp_float real() const
Definition: mpr_complex.h:234

◆ operator>=

bool operator>= ( const gmp_complex a,
const gmp_complex b 
)
friend

Definition at line 277 of file mpr_complex.h.

278 {
279  return ( a.real() >= b.real() );
280 }
gmp_float real() const
Definition: mpr_complex.h:234

Field Documentation

◆ i

gmp_float gmp_complex::i
private

Definition at line 181 of file mpr_complex.h.

◆ r

gmp_float gmp_complex::r
private

Definition at line 181 of file mpr_complex.h.


The documentation for this class was generated from the following files: