Loading...
Searching...
No Matches
mpr_complex.h File Reference
`#include "coeffs/si_gmp.h"`
`#include "coeffs/mpr_global.h"`

Go to the source code of this file.

## Data Structures

class | gmp_float
class | gmp_complex
| gmp_complex numbers based on More...

## Macros

#define | ZTOF 1
#define | QTOF 2
#define | RTOF 3
#define | CTOF 4

## 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.
char * | floatToStr (const gmp_float &r, const unsigned int oprec)
gmp_float | abs (const gmp_float &)
gmp_float | sqrt (const gmp_float &)
gmp_float | hypot (const gmp_float &, const gmp_float &)
gmp_float | sin (const gmp_float &)
gmp_float | cos (const gmp_float &)
gmp_float | log (const gmp_float &)
gmp_float | exp (const gmp_float &)
gmp_float | max (const gmp_float &, const gmp_float &)
gmp_float | numberToFloat (number num, const coeffs src)
gmp_float | numberFieldToFloat (number num, int src)
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)
gmp_float | abs (const gmp_complex &c)
gmp_complex | sqrt (const gmp_complex &x)
gmp_complex | numberToComplex (number num, const coeffs r)
char * | complexToStr (gmp_complex &c, const unsigned int oprec, const coeffs src)
bool | complexNearZero (gmp_complex *c, int digits)

## Macro Definition Documentation

## CTOF

#define CTOF 4

Definition at line 21 of file mpr_complex.h.

## QTOF

#define QTOF 2

Definition at line 19 of file mpr_complex.h.

## RTOF

#define RTOF 3

Definition at line 20 of file mpr_complex.h.

## ZTOF

#define ZTOF 1

Definition at line 18 of file mpr_complex.h.

## Function Documentation

## abs() [1/2]

gmp_float abs | ( | const gmp_complex & | c | ) |

inline

Definition at line 307 of file mpr_complex.h.

{
return hypot(c.real(),c.imag());
}
gmp_complex::imag
gmp_float imag() const
Definition mpr_complex.h:237
gmp_complex::real
gmp_float real() const
Definition mpr_complex.h:236
hypot
gmp_float hypot(const gmp_float &, const gmp_float &)
Definition mpr_complex.cc:340

## abs() [2/2]

gmp_float abs | ( | const gmp_float & | a | ) |

Definition at line 313 of file mpr_complex.cc.

{
gmp_float tmp;
mpf_abs( *(tmp._mpfp()), *a.mpfp() );
return tmp;
}
gmp_float
Definition mpr_complex.h:32
gmp_float::_mpfp
mpf_t * _mpfp()
Definition mpr_complex.h:136
gmp_float::mpfp
const mpf_t * mpfp() const
Definition mpr_complex.h:135

## complexNearZero()

bool complexNearZero | ( | gmp_complex * | c,
|  | int | digits )

Definition at line 754 of file mpr_complex.cc.

{
gmp_float eps,epsm;
if ( digits < 1 ) return true;
eps=pow(10.0,(int)digits);
//Print("eps: %s\n",floatToStr(eps,gmp_output_digits));
eps=(gmp_float)1.0/eps;
epsm=-eps;
//Print("eps: %s\n",floatToStr(eps,gmp_output_digits));
if ( c->real().sign() > 0 ) // +
return (c->real() < eps && (c->imag() < eps && c->imag() > epsm));
else // -
return (c->real() > epsm && (c->imag() < eps && c->imag() > epsm));
}
pow
Rational pow(const Rational &a, int e)
Definition GMPrat.cc:411
gmp_float::sign
int sign()
Definition mpr_complex.h:125

## complexToStr()

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

Definition at line 693 of file mpr_complex.cc.

{
const char * complex_parameter = "I";
int N = 1; // strlen(complex_parameter);
if (nCoeff_is_long_C(src))
{
complex_parameter = n_ParameterNames(src)[0];
N = strlen(complex_parameter);
}
assume( complex_parameter != NULL && N > 0);
char *out,*in_imag,*in_real;
c.SmallToZero();
if ( !c.imag().isZero() )
{
in_real=floatToStr( c.real(), oprec ); // get real part
in_imag=floatToStr( abs(c.imag()), oprec ); // get imaginary part
if (nCoeff_is_long_C(src))
{
int len=(strlen(in_real)+strlen(in_imag)+7+N)*sizeof(char);
out=(char*)omAlloc(len);
memset(out,0,len);
if ( !c.real().isZero() ) // (-23-i*5.43) or (15.1+i*5.3)
snprintf(out,len,"(%s%s%s*%s)",in_real,c.imag().sign()>=0?"+":"-",complex_parameter,in_imag);
else // (-i*43) or (i*34)
{
if (c.imag().isOne())
snprintf(out,len,"%s", complex_parameter);
else if (c.imag().isMOne())
snprintf(out,len,"-%s", complex_parameter);
else
snprintf(out,len,"(%s%s*%s)",c.imag().sign()>=0?"":"-", complex_parameter,in_imag);
}
}
else
{
int len=(strlen(in_real)+strlen(in_imag)+9) * sizeof(char);
out=(char*)omAlloc( len );
memset(out,0,len);
if ( !c.real().isZero() )
snprintf(out,len,"(%s%s%s)",in_real,c.imag().sign()>=0?"+I*":"-I*",in_imag);
else
snprintf(out,len,"(%s%s)",c.imag().sign()>=0?"I*":"-I*",in_imag);
}
omFree( (void *) in_real );
omFree( (void *) in_imag );
}
else
{
out= floatToStr( c.real(), oprec );
}
return out;
}
N
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
gmp_complex::SmallToZero
void SmallToZero()
Definition mpr_complex.cc:773
gmp_float::isOne
bool isOne() const
Definition mpr_complex.cc:257
gmp_float::isMOne
bool isMOne() const
Definition mpr_complex.cc:273
gmp_float::isZero
bool isZero() const
Definition mpr_complex.cc:252
n_ParameterNames
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition coeffs.h:773
nCoeff_is_long_C
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition coeffs.h:889
assume
#define assume(x)
Definition mod2.h:389
abs
gmp_float abs(const gmp_float &a)
Definition mpr_complex.cc:313
floatToStr
char * floatToStr(const gmp_float &r, const unsigned int oprec)
Definition mpr_complex.cc:567
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omFree
#define omFree(addr)
Definition omAllocDecl.h:261
NULL
#define NULL
Definition omList.c:12

## cos()

gmp_float cos | ( | const gmp_float & | a | ) |

Definition at line 330 of file mpr_complex.cc.

{
gmp_float tmp( cos((double)a) );
return tmp;
}
cos
gmp_float cos(const gmp_float &a)
Definition mpr_complex.cc:330

## exp()

gmp_float exp | ( | const gmp_float & | a | ) |

Definition at line 349 of file mpr_complex.cc.

{
gmp_float tmp( exp((double)a) );
return tmp;
}
exp
gmp_float exp(const gmp_float &a)
Definition mpr_complex.cc:349

## floatToStr()

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

Definition at line 567 of file mpr_complex.cc.

{
#if 1
mp_exp_t exponent;
int size,insize;
char *nout,*out,*in;
insize= (oprec+2) * sizeof(char) + 10;
in= (char*)omAlloc( insize );
mpf_get_str(in,&exponent,10,oprec,*(r.mpfp()));
//if ( (exponent > 0)
//&& (exponent < (int)oprec)
//&& (strlen(in)-(in[0]=='-'?1:0) == oprec) )
//{
// omFree( (void *) in );
// insize= (exponent+oprec+2) * sizeof(char) + 10;
// in= (char*)omAlloc( insize );
// int newprec= exponent+oprec;
// mpf_get_str(in,&exponent,10,newprec,*(r.mpfp()));
//}
nout= nicifyFloatStr( in, exponent, oprec, &size, SIGN_EMPTY );
omFree( (void *) in );
out= (char*)omAlloc( (strlen(nout)+1) * sizeof(char) );
strcpy( out, nout );
omFree( (void *) nout );
return out;
#else
// for testing purpose...
char *out= (char*)omAlloc(1024);
snprintf(out,1024,"% .10f",(double)r);
return out;
#endif
}
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
exponent
#define exponent
Definition interpolation.cc:31
SIGN_EMPTY
#define SIGN_EMPTY
Definition mpr_complex.cc:37
nicifyFloatStr
char * nicifyFloatStr(char *in, mp_exp_t exponent, size_t oprec, int *size, int thesign)
Definition mpr_complex.cc:477

## hypot()

gmp_float hypot | ( | const gmp_float & | a,
|  | const gmp_float & | b )

Definition at line 340 of file mpr_complex.cc.

{
#if 1
return ( sqrt( (a*a) + (b*b) ) );
#else
gmp_float tmp( hypot( (double)a, (double)b ) );
return tmp;
#endif
}
b
CanonicalForm b
Definition cfModGcd.cc:4111
sqrt
gmp_float sqrt(const gmp_float &a)
Definition mpr_complex.cc:319
hypot
gmp_float hypot(const gmp_float &a, const gmp_float &b)
Definition mpr_complex.cc:340

## log()

gmp_float log | ( | const gmp_float & | a | ) |

Definition at line 335 of file mpr_complex.cc.

{
gmp_float tmp( log((double)a) );
return tmp;
}
log
gmp_float log(const gmp_float &a)
Definition mpr_complex.cc:335

## max()

gmp_float max | ( | const gmp_float & | a,
|  | const gmp_float & | b )

Definition at line 354 of file mpr_complex.cc.

{
gmp_float tmp;
a > b ? tmp= a : tmp= b;
return tmp;
}

## numberFieldToFloat()

gmp_float numberFieldToFloat | ( | number | num,
|  | int | src )

Definition at line 430 of file mpr_complex.cc.

{
gmp_float r;
switch (cf)
{
case QTOF:
if ( num != NULL )
{
if (SR_HDL(num) & SR_INT)
{
r = gmp_float(SR_TO_INT(num));
}
else
{
if ( num->s != 3 )
{
r= gmp_float(num->z);
r/= gmp_float(num->n);
}
else
{
r= num->z;
}
}
}
else
{
r= 0.0;
}
break;
case RTOF:
r= *(gmp_float*)num;
break;
case CTOF:
WerrorS("Can not map from field C to field R!");
break;
case ZTOF:
default:
WerrorS("Ground field not implemented!");
} // switch
return r;
}
num
CanonicalForm num(const CanonicalForm &f)
Definition canonicalform.h:337
cf
CanonicalForm cf
Definition cfModGcd.cc:4091
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
SR_INT
#define SR_INT
Definition longrat.h:67
SR_HDL
#define SR_HDL(A)
Definition mpr_complex.cc:32
SR_TO_INT
#define SR_TO_INT(SR)
Definition mpr_complex.cc:33
RTOF
#define RTOF
Definition mpr_complex.h:20
QTOF
#define QTOF
Definition mpr_complex.h:19
ZTOF
#define ZTOF
Definition mpr_complex.h:18
CTOF
#define CTOF
Definition mpr_complex.h:21

## numberToComplex()

gmp_complex numberToComplex | ( | number | num,
|  | const coeffs | r )

inline

Definition at line 314 of file mpr_complex.h.

{
if (nCoeff_is_long_C(r))
{
return *(gmp_complex*)num;
}
else
{
return gmp_complex( numberToFloat(num, r) );
}
}
gmp_complex
gmp_complex numbers based on
Definition mpr_complex.h:181
numberToFloat
gmp_float numberToFloat(number num, const coeffs src)
Definition mpr_complex.cc:364

## numberToFloat()

gmp_float numberToFloat | ( | number | num,
|  | const coeffs | src )

Definition at line 364 of file mpr_complex.cc.

{
gmp_float r;
if ( nCoeff_is_Q(src) )
{
if ( num != NULL )
{
if (SR_HDL(num) & SR_INT)
{
//n_Print(num, src);printf("\n");
int nn = SR_TO_INT(num);
if((long)nn == SR_TO_INT(num))
r = SR_TO_INT(num);
else
r = gmp_float(SR_TO_INT(num));
//int dd = 20;
//gmp_printf("\nr = %.*Ff\n",dd,*r.mpfp());
//getchar();
}
else
{
if ( num->s == 0 )
{
nlNormalize( num, src ); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r); // FIXME
}
if (SR_HDL(num) & SR_INT)
{
r= SR_TO_INT(num);
}
else
{
if ( num->s != 3 )
{
r= num->z;
r/= (gmp_float)num->n;
}
else
{
r= num->z;
}
}
}
}
else
{
r= 0.0;
}
}
else if (nCoeff_is_long_R(src) || nCoeff_is_long_C(src))
{
r= *(gmp_float*)num;
}
else if ( nCoeff_is_R(src) )
{
// Add some code here :-)
WerrorS("Ground field not implemented!");
}
else
{
WerrorS("Ground field not implemented!");
}
return r;
}
nCoeff_is_long_R
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition coeffs.h:886
nCoeff_is_Q
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition coeffs.h:801
nCoeff_is_R
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition coeffs.h:831
nlNormalize
void nlNormalize(number &x, const coeffs r)
Definition longrat.cc:1481

## operator*()

gmp_complex operator* | ( | const gmp_complex & | a,
|  | const gmp_float | b_d )

inline

Definition at line 257 of file mpr_complex.h.

{
return gmp_complex( a.r * b_d, a.i * b_d );
}
gmp_complex::i
gmp_float i
Definition mpr_complex.h:183
gmp_complex::r
gmp_float r
Definition mpr_complex.h:183

## operator+()

gmp_complex operator+ | ( | const gmp_complex & | a,
|  | const gmp_float | b_d )

inline

Definition at line 249 of file mpr_complex.h.

{
return gmp_complex( a.r + b_d, a.i );
}

## operator-()

gmp_complex operator- | ( | const gmp_complex & | a,
|  | const gmp_float | b_d )

inline

Definition at line 253 of file mpr_complex.h.

{
return gmp_complex( a.r - b_d, a.i );
}

## operator/()

gmp_complex operator/ | ( | const gmp_complex & | a,
|  | const gmp_float | b_d )

inline

Definition at line 261 of file mpr_complex.h.

{
return gmp_complex( a.r / b_d, a.i / b_d );
}

## operator<()

bool operator< | ( | const gmp_complex & | a,
|  | const gmp_complex & | b )

inline

Definition at line 275 of file mpr_complex.h.

{
return ( a.real() < b.real() );
}

## operator<=()

bool operator<= | ( | const gmp_complex & | a,
|  | const gmp_complex & | b )

inline

Definition at line 283 of file mpr_complex.h.

{
return ( a.real() <= b.real() );
}

## operator==()

bool operator== | ( | const gmp_complex & | a,
|  | const gmp_complex & | b )

inline

Definition at line 267 of file mpr_complex.h.

{
return ( b.real() == a.real() ) && ( b.imag() == a.imag() );
}

## operator>()

bool operator> | ( | const gmp_complex & | a,
|  | const gmp_complex & | b )

inline

Definition at line 271 of file mpr_complex.h.

{
return ( a.real() > b.real() );
}

## operator>=()

bool operator>= | ( | const gmp_complex & | a,
|  | const gmp_complex & | b )

inline

Definition at line 279 of file mpr_complex.h.

{
return ( a.real() >= b.real() );
}

## 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 60 of file mpr_complex.cc.

{
size_t bits = 1 + (size_t) ((float)digits * 3.5);
size_t rb = 1 + (size_t) ((float)rest * 3.5);
size_t db = bits+rb;
gmp_output_digits= digits;
mpf_set_default_prec( db );
if (diff!=NULL) delete diff;
diff=new gmp_float(0.0);
mpf_set_prec(*diff->_mpfp(),32);
if (gmpRel!=NULL) delete gmpRel;
gmpRel=new gmp_float(0.0);
mpf_set_prec(*gmpRel->_mpfp(),32);
mpf_set_d(*gmpRel->_mpfp(),0.1);
mpf_pow_ui(*gmpRel->_mpfp(),*gmpRel->_mpfp(),digits);
}
gmp_output_digits
EXTERN_VAR size_t gmp_output_digits
Definition mpr_base.h:115
gmpRel
STATIC_VAR gmp_float * gmpRel
Definition mpr_complex.cc:44
diff
STATIC_VAR gmp_float * diff
Definition mpr_complex.cc:45

## sin()

gmp_float sin | ( | const gmp_float & | a | ) |

Definition at line 325 of file mpr_complex.cc.

{
gmp_float tmp( sin((double)a) );
return tmp;
}
sin
gmp_float sin(const gmp_float &a)
Definition mpr_complex.cc:325

## sqrt() [1/2]

gmp_complex sqrt | ( | const gmp_complex & | x | ) |

Definition at line 665 of file mpr_complex.cc.

{
gmp_float r = abs(x);
gmp_float nr, ni;
if (r == (gmp_float) 0.0)
{
nr = ni = r;
}
else if ( x.real() > (gmp_float)0)
{
nr = sqrt((gmp_float)0.5 * (r + x.real()));
ni = x.imag() / nr / (gmp_float)2;
}
else
{
ni = sqrt((gmp_float)0.5 * (r - x.real()));
if (x.imag() < (gmp_float)0)
{
ni = - ni;
}
nr = x.imag() / ni / (gmp_float)2;
}
gmp_complex tmp(nr, ni);
return tmp;
}
x
Variable x
Definition cfModGcd.cc:4090

## sqrt() [2/2]

gmp_float sqrt | ( | const gmp_float & | a | ) |

Definition at line 319 of file mpr_complex.cc.

{
gmp_float tmp;
mpf_sqrt( *(tmp._mpfp()), *a.mpfp() );
return tmp;
}