Macros | Functions | Variables
mpr_complex.cc File Reference
#include <misc/auxiliary.h>
#include <omalloc/omalloc.h>
#include <reporter/reporter.h>
#include <coeffs/coeffs.h>
#include <coeffs/numbers.h>
#include <coeffs/mpr_complex.h>
#include "longrat.h"
#include <math.h>

Go to the source code of this file.

Macros

#define SR_HDL(A)   ((long)(A))
 
#define SR_TO_INT(SR)   (((long)SR) >> 2)
 
#define SIGN_PLUS   1
 
#define SIGN_SPACE   2
 
#define SIGN_EMPTY   4
 
#define EXTRABYTES   4
 
#define DEFPREC   20
 

Functions

void setGMPFloatDigits (size_t digits, size_t rest)
 Set size of mantissa digits - the number of output digits (basis 10) the size of mantissa consists of two parts: the "output" part a and the "rest" part b. More...
 
gmp_float operator+ (const gmp_float &a, const gmp_float &b)
 
gmp_float operator- (const gmp_float &a, const gmp_float &b)
 
gmp_float operator* (const gmp_float &a, const gmp_float &b)
 
gmp_float operator/ (const gmp_float &a, const gmp_float &b)
 
bool operator== (const gmp_float &a, const gmp_float &b)
 
bool operator> (const gmp_float &a, const gmp_float &b)
 
bool operator< (const gmp_float &a, const gmp_float &b)
 
bool operator>= (const gmp_float &a, const gmp_float &b)
 
bool operator<= (const gmp_float &a, const gmp_float &b)
 
gmp_float operator- (const gmp_float &a)
 
gmp_float abs (const gmp_float &a)
 
gmp_float sqrt (const gmp_float &a)
 
gmp_float sin (const gmp_float &a)
 
gmp_float cos (const gmp_float &a)
 
gmp_float log (const gmp_float &a)
 
gmp_float hypot (const gmp_float &a, const gmp_float &b)
 
gmp_float exp (const gmp_float &a)
 
gmp_float max (const gmp_float &a, const gmp_float &b)
 
gmp_float numberToFloat (number num, const coeffs src)
 
gmp_float numberFieldToFloat (number num, int cf)
 
char * nicifyFloatStr (char *in, mp_exp_t exponent, size_t oprec, int *size, int thesign)
 
char * floatToStr (const gmp_float &r, const unsigned int oprec)
 
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 sqrt (const gmp_complex &x)
 
char * complexToStr (gmp_complex &c, const unsigned int oprec, const coeffs src)
 
bool complexNearZero (gmp_complex *c, int digits)
 

Variables

size_t gmp_output_digits = DEFPREC
 
static gmp_floatgmpRel =NULL
 
static gmp_floatdiff =NULL
 

Macro Definition Documentation

◆ DEFPREC

#define DEFPREC   20

Definition at line 43 of file mpr_complex.cc.

◆ EXTRABYTES

#define EXTRABYTES   4

Definition at line 41 of file mpr_complex.cc.

◆ SIGN_EMPTY

#define SIGN_EMPTY   4

Definition at line 39 of file mpr_complex.cc.

◆ SIGN_PLUS

#define SIGN_PLUS   1

Definition at line 37 of file mpr_complex.cc.

◆ SIGN_SPACE

#define SIGN_SPACE   2

Definition at line 38 of file mpr_complex.cc.

◆ SR_HDL

#define SR_HDL (   A)    ((long)(A))

Definition at line 34 of file mpr_complex.cc.

◆ SR_TO_INT

#define SR_TO_INT (   SR)    (((long)SR) >> 2)

Definition at line 35 of file mpr_complex.cc.

Function Documentation

◆ abs()

gmp_float abs ( const gmp_float a)

Definition at line 323 of file mpr_complex.cc.

324 {
325  gmp_float tmp;
326  mpf_abs( *(tmp._mpfp()), *a.mpfp() );
327  return tmp;
328 }
mpf_t * _mpfp()
Definition: mpr_complex.h:134
const mpf_t * mpfp() const
Definition: mpr_complex.h:133

◆ complexNearZero()

bool complexNearZero ( gmp_complex c,
int  digits 
)

Definition at line 767 of file mpr_complex.cc.

768 {
769  gmp_float eps,epsm;
770 
771  if ( digits < 1 ) return true;
772 
773  eps=pow(10.0,(int)digits);
774  //Print("eps: %s\n",floatToStr(eps,gmp_output_digits));
775  eps=(gmp_float)1.0/eps;
776  epsm=-eps;
777 
778  //Print("eps: %s\n",floatToStr(eps,gmp_output_digits));
779 
780  if ( c->real().sign() > 0 ) // +
781  return (c->real() < eps && (c->imag() < eps && c->imag() > epsm));
782  else // -
783  return (c->real() > epsm && (c->imag() < eps && c->imag() > epsm));
784 }
gmp_float real() const
Definition: mpr_complex.h:234
int sign()
Definition: mpr_complex.h:123
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:418
gmp_float imag() const
Definition: mpr_complex.h:235

◆ complexToStr()

char* complexToStr ( gmp_complex c,
const unsigned int  oprec,
const coeffs  src 
)

Definition at line 706 of file mpr_complex.cc.

707 {
708  const char * complex_parameter = "I";
709  int N = 1; // strlen(complex_parameter);
710 
711  if (nCoeff_is_long_C(src))
712  {
713  complex_parameter = n_ParameterNames(src)[0];
714  N = strlen(complex_parameter);
715  }
716 
717  assume( complex_parameter != NULL && N > 0);
718 
719  char *out,*in_imag,*in_real;
720 
721  c.SmallToZero();
722  if ( !c.imag().isZero() )
723  {
724 
725  in_real=floatToStr( c.real(), oprec ); // get real part
726  in_imag=floatToStr( abs(c.imag()), oprec ); // get imaginary part
727 
728  if (nCoeff_is_long_C(src))
729  {
730  int len=(strlen(in_real)+strlen(in_imag)+7+N)*sizeof(char);
731  out=(char*)omAlloc(len);
732  memset(out,0,len);
733  if ( !c.real().isZero() ) // (-23-i*5.43) or (15.1+i*5.3)
734  sprintf(out,"(%s%s%s*%s)",in_real,c.imag().sign()>=0?"+":"-",complex_parameter,in_imag);
735  else // (-i*43) or (i*34)
736  {
737  if (c.imag().isOne())
738  sprintf(out,"%s", complex_parameter);
739  else if (c.imag().isMOne())
740  sprintf(out,"-%s", complex_parameter);
741  else
742  sprintf(out,"(%s%s*%s)",c.imag().sign()>=0?"":"-", complex_parameter,in_imag);
743  }
744  }
745  else
746  {
747  int len=(strlen(in_real)+strlen(in_imag)+9) * sizeof(char);
748  out=(char*)omAlloc( len );
749  memset(out,0,len);
750  if ( !c.real().isZero() )
751  sprintf(out,"(%s%s%s)",in_real,c.imag().sign()>=0?"+I*":"-I*",in_imag);
752  else
753  sprintf(out,"(%s%s)",c.imag().sign()>=0?"I*":"-I*",in_imag);
754  }
755  omFree( (void *) in_real );
756  omFree( (void *) in_imag );
757  }
758  else
759  {
760  out= floatToStr( c.real(), oprec );
761  }
762 
763  return out;
764 }
void SmallToZero()
Definition: mpr_complex.cc:786
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
gmp_float real() const
Definition: mpr_complex.h:234
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition: coeffs.h:911
#define omAlloc(size)
Definition: omAllocDecl.h:210
bool isZero() const
Definition: mpr_complex.cc:254
int sign()
Definition: mpr_complex.h:123
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
#define omFree(addr)
Definition: omAllocDecl.h:261
#define assume(x)
Definition: mod2.h:394
gmp_float abs(const gmp_float &a)
Definition: mpr_complex.cc:323
bool isOne() const
Definition: mpr_complex.cc:259
#define NULL
Definition: omList.c:10
char * floatToStr(const gmp_float &r, const unsigned int oprec)
Definition: mpr_complex.cc:580
bool isMOne() const
Definition: mpr_complex.cc:275
gmp_float imag() const
Definition: mpr_complex.h:235

◆ cos()

gmp_float cos ( const gmp_float a)

Definition at line 340 of file mpr_complex.cc.

341 {
342  gmp_float tmp( cos((double)a) );
343  return tmp;
344 }
gmp_float cos(const gmp_float &a)
Definition: mpr_complex.cc:340

◆ exp()

gmp_float exp ( const gmp_float a)

Definition at line 359 of file mpr_complex.cc.

360 {
361  gmp_float tmp( exp((double)a) );
362  return tmp;
363 }
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:359

◆ floatToStr()

char* floatToStr ( const gmp_float r,
const unsigned int  oprec 
)

Definition at line 580 of file mpr_complex.cc.

581 {
582 #if 1
583  mp_exp_t exponent;
584  int size,insize;
585  char *nout,*out,*in;
586 
587  insize= (oprec+2) * sizeof(char) + 10;
588  in= (char*)omAlloc( insize );
589 
590  mpf_get_str(in,&exponent,10,oprec,*(r.mpfp()));
591 
592  //if ( (exponent > 0)
593  //&& (exponent < (int)oprec)
594  //&& (strlen(in)-(in[0]=='-'?1:0) == oprec) )
595  //{
596  // omFree( (void *) in );
597  // insize= (exponent+oprec+2) * sizeof(char) + 10;
598  // in= (char*)omAlloc( insize );
599  // int newprec= exponent+oprec;
600  // mpf_get_str(in,&exponent,10,newprec,*(r.mpfp()));
601  //}
602  nout= nicifyFloatStr( in, exponent, oprec, &size, SIGN_EMPTY );
603  omFree( (void *) in );
604  out= (char*)omAlloc( (strlen(nout)+1) * sizeof(char) );
605  strcpy( out, nout );
606  omFree( (void *) nout );
607 
608  return out;
609 #else
610  // for testing purpose...
611  char *out= (char*)omAlloc( (1024) * sizeof(char) );
612  sprintf(out,"% .10f",(double)r);
613  return out;
614 #endif
615 }
char * nicifyFloatStr(char *in, mp_exp_t exponent, size_t oprec, int *size, int thesign)
Definition: mpr_complex.cc:487
#define SIGN_EMPTY
Definition: mpr_complex.cc:39
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
const mpf_t * mpfp() const
Definition: mpr_complex.h:133
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
int exponent(const CanonicalForm &f, int q)
int exponent ( const CanonicalForm & f, int q )

◆ hypot()

gmp_float hypot ( const gmp_float a,
const gmp_float b 
)

Definition at line 350 of file mpr_complex.cc.

351 {
352 #if 1
353  return ( sqrt( (a*a) + (b*b) ) );
354 #else
355  gmp_float tmp( hypot( (double)a, (double)b ) );
356  return tmp;
357 #endif
358 }
gmp_float hypot(const gmp_float &a, const gmp_float &b)
Definition: mpr_complex.cc:350
gmp_float sqrt(const gmp_float &a)
Definition: mpr_complex.cc:329

◆ log()

gmp_float log ( const gmp_float a)

Definition at line 345 of file mpr_complex.cc.

346 {
347  gmp_float tmp( log((double)a) );
348  return tmp;
349 }
gmp_float log(const gmp_float &a)
Definition: mpr_complex.cc:345

◆ max()

gmp_float max ( const gmp_float a,
const gmp_float b 
)

Definition at line 364 of file mpr_complex.cc.

365 {
366  gmp_float tmp;
367  a > b ? tmp= a : tmp= b;
368  return tmp;
369 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213

◆ nicifyFloatStr()

char* nicifyFloatStr ( char *  in,
mp_exp_t  exponent,
size_t  oprec,
int *  size,
int  thesign 
)

Definition at line 487 of file mpr_complex.cc.

488 {
489  char *out;
490 
491  int sign= (in[0] == '-') ? 1 : 0;
492  char csign[2];
493 
494  switch (thesign)
495  {
496  case SIGN_PLUS:
497  sign ? strcpy(csign,"-") : strcpy(csign,"+"); //+123, -123
498  break;
499  case SIGN_SPACE:
500  sign ? strcpy(csign,"-") : strcpy(csign," "); // 123, -123
501  break;
502  case SIGN_EMPTY:
503  default:
504  sign ? strcpy(csign,"-") : strcpy(csign,""); //123, -123
505  break;
506  }
507 
508  if ( strlen(in) == 0 )
509  {
510  *size= 2*sizeof(char);
511  return omStrDup("0");
512  }
513 
514  if ( ((unsigned int)ABS(exponent) <= oprec)
515  /*|| (exponent+sign >= (int)strlen(in))*/ )
516  {
517  if ( exponent+sign < (int)strlen(in) )
518  {
519  int eexponent= (exponent >= 0) ? 0 : -exponent;
520  int eeexponent= (exponent >= 0) ? exponent : 0;
521  *size= (strlen(in)+15+eexponent) * sizeof(char);
522  out= (char*)omAlloc(*size);
523  memset(out,0,*size);
524 
525  strcpy(out,csign);
526  strncat(out,in+sign,eeexponent);
527 
528  if (exponent == 0)
529  strcat(out,"0.");
530  else if ( exponent > 0 )
531  strcat(out,".");
532  else
533  {
534  strcat(out,"0.");
535  memset(out+strlen(out),'0',eexponent);
536  }
537  strcat(out,in+sign+eeexponent);
538  }
539  else if ( exponent+sign > (int)strlen(in) )
540  {
541  *size= (strlen(in)+exponent+12)*sizeof(char);
542  out= (char*)omAlloc(*size);
543  memset(out,0,*size);
544  sprintf(out,"%s%s",csign,in+sign);
545  memset(out+strlen(out),'0',exponent-strlen(in)+sign);
546  }
547  else
548  {
549  *size= (strlen(in)+2) * sizeof(char) + 10;
550  out= (char*)omAlloc(*size);
551  memset(out,0,*size);
552  sprintf(out,"%s%s",csign,in+sign);
553  }
554  }
555  else
556  {
557 // if ( exponent > 0 )
558 // {
559  int c=1,d=10;
560  while ( exponent / d > 0 )
561  { // count digits
562  d*=10;
563  c++;
564  }
565  *size= (strlen(in)+12+c) * sizeof(char) + 10;
566  out= (char*)omAlloc(*size);
567  memset(out,0,*size);
568  sprintf(out,"%s0.%se%s%d",csign,in+sign,exponent>=0?"+":"",(int)exponent);
569 // }
570 // else
571 // {
572 // *size=2;
573 // out= (char*)omAlloc(*size);
574 // strcpy(out,"0");
575 // }
576  }
577  return out;
578 }
#define SIGN_EMPTY
Definition: mpr_complex.cc:39
#define SIGN_SPACE
Definition: mpr_complex.cc:38
#define SIGN_PLUS
Definition: mpr_complex.cc:37
#define omAlloc(size)
Definition: omAllocDecl.h:210
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define ABS(x)
Definition: auxiliary.h:111
int exponent(const CanonicalForm &f, int q)
int exponent ( const CanonicalForm & f, int q )
static int sign(int x)
Definition: ring.cc:3333
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ numberFieldToFloat()

gmp_float numberFieldToFloat ( number  num,
int  cf 
)

Definition at line 440 of file mpr_complex.cc.

441 {
442  gmp_float r;
443 
444  switch (cf)
445  {
446  case QTOF:
447  if ( num != NULL )
448  {
449  if (SR_HDL(num) & SR_INT)
450  {
451  r = gmp_float(SR_TO_INT(num));
452  }
453  else
454  {
455  if ( num->s != 3 )
456  {
457  r= gmp_float(num->z);
458  r/= gmp_float(num->n);
459  }
460  else
461  {
462  r= num->z;
463  }
464  }
465  }
466  else
467  {
468  r= 0.0;
469  }
470  break;
471  case RTOF:
472  r= *(gmp_float*)num;
473  break;
474  case CTOF:
475  WerrorS("Can not map from field C to field R!");
476  break;
477  case ZTOF:
478  default:
479  WerrorS("Ground field not implemented!");
480  } // switch
481 
482  return r;
483 }
#define ZTOF
Definition: mpr_complex.h:18
CanonicalForm num(const CanonicalForm &f)
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define CTOF
Definition: mpr_complex.h:21
const ring r
Definition: syzextra.cc:208
#define QTOF
Definition: mpr_complex.h:19
#define SR_TO_INT(SR)
Definition: mpr_complex.cc:35
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define NULL
Definition: omList.c:10
#define SR_HDL(A)
Definition: mpr_complex.cc:34
#define SR_INT
Definition: longrat.h:68
#define RTOF
Definition: mpr_complex.h:20

◆ numberToFloat()

gmp_float numberToFloat ( number  num,
const coeffs  src 
)

Definition at line 374 of file mpr_complex.cc.

375 {
376  gmp_float r;
377 
378  if ( nCoeff_is_Q(src) )
379  {
380  if ( num != NULL )
381  {
382  if (SR_HDL(num) & SR_INT)
383  {
384  //n_Print(num, src);printf("\n");
385  int nn = SR_TO_INT(num);
386  if((long)nn == SR_TO_INT(num))
387  r = SR_TO_INT(num);
388  else
389  r = gmp_float(SR_TO_INT(num));
390  //int dd = 20;
391  //gmp_printf("\nr = %.*Ff\n",dd,*r.mpfp());
392  //getchar();
393  }
394  else
395  {
396  if ( num->s == 0 )
397  {
398  nlNormalize( num, src ); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r); // FIXME
399  }
400  if (SR_HDL(num) & SR_INT)
401  {
402  r= SR_TO_INT(num);
403  }
404  else
405  {
406  if ( num->s != 3 )
407  {
408  r= num->z;
409  r/= (gmp_float)num->n;
410  }
411  else
412  {
413  r= num->z;
414  }
415  }
416  }
417  }
418  else
419  {
420  r= 0.0;
421  }
422  }
423  else if (nCoeff_is_long_R(src) || nCoeff_is_long_C(src))
424  {
425  r= *(gmp_float*)num;
426  }
427  else if ( nCoeff_is_R(src) )
428  {
429  // Add some code here :-)
430  WerrorS("Ground field not implemented!");
431  }
432  else
433  {
434  WerrorS("Ground field not implemented!");
435  }
436 
437  return r;
438 }
CanonicalForm num(const CanonicalForm &f)
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:908
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:853
void WerrorS(const char *s)
Definition: feFopen.cc:24
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:840
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition: coeffs.h:911
const ring r
Definition: syzextra.cc:208
#define SR_TO_INT(SR)
Definition: mpr_complex.cc:35
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1349
#define NULL
Definition: omList.c:10
#define SR_HDL(A)
Definition: mpr_complex.cc:34
#define SR_INT
Definition: longrat.h:68

◆ operator*() [1/2]

gmp_float operator* ( const gmp_float a,
const gmp_float b 
)

Definition at line 181 of file mpr_complex.cc.

182 {
183  gmp_float tmp( a );
184  tmp *= b;
185  return tmp;
186 }
const poly b
Definition: syzextra.cc:213

◆ operator*() [2/2]

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

Definition at line 629 of file mpr_complex.cc.

630 {
631  return gmp_complex( a.r * b.r - a.i * b.i,
632  a.r * b.i + a.i * b.r);
633 }
gmp_float i
Definition: mpr_complex.h:181
gmp_complex numbers based on
Definition: mpr_complex.h:178
gmp_float r
Definition: mpr_complex.h:181

◆ operator+() [1/2]

gmp_float operator+ ( const gmp_float a,
const gmp_float b 
)

Definition at line 169 of file mpr_complex.cc.

170 {
171  gmp_float tmp( a );
172  tmp += b;
173  return tmp;
174 }
const poly b
Definition: syzextra.cc:213

◆ operator+() [2/2]

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

Definition at line 621 of file mpr_complex.cc.

622 {
623  return gmp_complex( a.r + b.r, a.i + b.i );
624 }
gmp_float i
Definition: mpr_complex.h:181
gmp_complex numbers based on
Definition: mpr_complex.h:178
gmp_float r
Definition: mpr_complex.h:181

◆ operator-() [1/3]

gmp_float operator- ( const gmp_float a,
const gmp_float b 
)

Definition at line 175 of file mpr_complex.cc.

176 {
177  gmp_float tmp( a );
178  tmp -= b;
179  return tmp;
180 }
const poly b
Definition: syzextra.cc:213

◆ operator-() [2/3]

gmp_float operator- ( const gmp_float a)

Definition at line 316 of file mpr_complex.cc.

317 {
318  gmp_float tmp;
319  mpf_neg( *(tmp._mpfp()), *(a.mpfp()) );
320  return tmp;
321 }
mpf_t * _mpfp()
Definition: mpr_complex.h:134
const mpf_t * mpfp() const
Definition: mpr_complex.h:133

◆ operator-() [3/3]

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

Definition at line 625 of file mpr_complex.cc.

626 {
627  return gmp_complex( a.r - b.r, a.i - b.i );
628 }
gmp_float i
Definition: mpr_complex.h:181
gmp_complex numbers based on
Definition: mpr_complex.h:178
gmp_float r
Definition: mpr_complex.h:181

◆ operator/() [1/2]

gmp_float operator/ ( const gmp_float a,
const gmp_float b 
)

Definition at line 187 of file mpr_complex.cc.

188 {
189  gmp_float tmp( a );
190  tmp /= b;
191  return tmp;
192 }
const poly b
Definition: syzextra.cc:213

◆ operator/() [2/2]

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

Definition at line 634 of file mpr_complex.cc.

635 {
636  gmp_float d = b.r*b.r + b.i*b.i;
637  return gmp_complex( (a.r * b.r + a.i * b.i) / d,
638  (a.i * b.r - a.r * b.i) / d);
639 }
gmp_float i
Definition: mpr_complex.h:181
gmp_complex numbers based on
Definition: mpr_complex.h:178
gmp_float r
Definition: mpr_complex.h:181

◆ operator<()

bool operator< ( const gmp_float a,
const gmp_float b 
)

Definition at line 296 of file mpr_complex.cc.

297 {
298  if (a.t == b.t)
299  return false;
300  return mpf_cmp( a.t, b.t ) < 0;
301 }

◆ operator<=()

bool operator<= ( const gmp_float a,
const gmp_float b 
)

Definition at line 308 of file mpr_complex.cc.

309 {
310  if (a.t == b.t)
311  return true;
312  return mpf_cmp( a.t, b.t ) <= 0;
313 }

◆ operator==()

bool operator== ( const gmp_float a,
const gmp_float b 
)

Definition at line 239 of file mpr_complex.cc.

240 {
241  if(mpf_sgn(a.t) != mpf_sgn(b.t))
242  return false;
243  if((mpf_sgn(a.t)==0) && (mpf_sgn(b.t)==0))
244  return true;
245  mpf_sub(diff->t, a.t, b.t);
246  mpf_div(diff->t, diff->t, a.t);
247  mpf_abs(diff->t, diff->t);
248  if(mpf_cmp(diff->t, gmpRel->t) < 0)
249  return true;
250  else
251  return false;
252 }
static gmp_float * diff
Definition: mpr_complex.cc:47
static gmp_float * gmpRel
Definition: mpr_complex.cc:46

◆ operator>()

bool operator> ( const gmp_float a,
const gmp_float b 
)

Definition at line 290 of file mpr_complex.cc.

291 {
292  if (a.t == b.t)
293  return false;
294  return mpf_cmp( a.t, b.t ) > 0;
295 }

◆ operator>=()

bool operator>= ( const gmp_float a,
const gmp_float b 
)

Definition at line 302 of file mpr_complex.cc.

303 {
304  if (a.t == b.t)
305  return true;
306  return mpf_cmp( a.t, b.t ) >= 0;
307 }

◆ setGMPFloatDigits()

void setGMPFloatDigits ( size_t  digits,
size_t  rest 
)

Set size of mantissa digits - the number of output digits (basis 10) the size of mantissa consists of two parts: the "output" part a and the "rest" part b.

According to the GMP-precision digits is recomputed to bits (basis 2). Two numbers a, b are equal if | a - b | < | a | * 0.1^digits . In this case we have a - b = 0 . The epsilon e is e=0.1^(digits+rest) with 1+e != 1, but 1+0.1*e = 1.

Definition at line 62 of file mpr_complex.cc.

63 {
64  size_t bits = 1 + (size_t) ((float)digits * 3.5);
65  size_t rb = 1 + (size_t) ((float)rest * 3.5);
66  size_t db = bits+rb;
67  gmp_output_digits= digits;
68  mpf_set_default_prec( db );
69  if (diff!=NULL) delete diff;
70  diff=new gmp_float(0.0);
71  mpf_set_prec(*diff->_mpfp(),32);
72  if (gmpRel!=NULL) delete gmpRel;
73  gmpRel=new gmp_float(0.0);
74  mpf_set_prec(*gmpRel->_mpfp(),32);
75  mpf_set_d(*gmpRel->_mpfp(),0.1);
76  mpf_pow_ui(*gmpRel->_mpfp(),*gmpRel->_mpfp(),digits);
77 }
static gmp_float * diff
Definition: mpr_complex.cc:47
mpf_t * _mpfp()
Definition: mpr_complex.h:134
#define NULL
Definition: omList.c:10
static gmp_float * gmpRel
Definition: mpr_complex.cc:46
size_t gmp_output_digits
Definition: mpr_complex.cc:44

◆ sin()

gmp_float sin ( const gmp_float a)

Definition at line 335 of file mpr_complex.cc.

336 {
337  gmp_float tmp( sin((double)a) );
338  return tmp;
339 }
gmp_float sin(const gmp_float &a)
Definition: mpr_complex.cc:335

◆ sqrt() [1/2]

gmp_float sqrt ( const gmp_float a)

Definition at line 329 of file mpr_complex.cc.

330 {
331  gmp_float tmp;
332  mpf_sqrt( *(tmp._mpfp()), *a.mpfp() );
333  return tmp;
334 }
mpf_t * _mpfp()
Definition: mpr_complex.h:134
const mpf_t * mpfp() const
Definition: mpr_complex.h:133

◆ sqrt() [2/2]

gmp_complex sqrt ( const gmp_complex x)

Definition at line 678 of file mpr_complex.cc.

679 {
680  gmp_float r = abs(x);
681  gmp_float nr, ni;
682  if (r == (gmp_float) 0.0)
683  {
684  nr = ni = r;
685  }
686  else if ( x.real() > (gmp_float)0)
687  {
688  nr = sqrt((gmp_float)0.5 * (r + x.real()));
689  ni = x.imag() / nr / (gmp_float)2;
690  }
691  else
692  {
693  ni = sqrt((gmp_float)0.5 * (r - x.real()));
694  if (x.imag() < (gmp_float)0)
695  {
696  ni = - ni;
697  }
698  nr = x.imag() / ni / (gmp_float)2;
699  }
700  gmp_complex tmp(nr, ni);
701  return tmp;
702 }
gmp_float real() const
Definition: mpr_complex.h:234
gmp_complex numbers based on
Definition: mpr_complex.h:178
const ring r
Definition: syzextra.cc:208
gmp_float sqrt(const gmp_float &a)
Definition: mpr_complex.cc:329
gmp_float abs(const gmp_float &a)
Definition: mpr_complex.cc:323
gmp_float imag() const
Definition: mpr_complex.h:235

Variable Documentation

◆ diff

gmp_float* diff =NULL
static

Definition at line 47 of file mpr_complex.cc.

◆ gmp_output_digits

size_t gmp_output_digits = DEFPREC

Definition at line 44 of file mpr_complex.cc.

◆ gmpRel

gmp_float* gmpRel =NULL
static

Definition at line 46 of file mpr_complex.cc.