My Project
Functions
gnumpc.cc File Reference
#include "misc/auxiliary.h"
#include "misc/mylimits.h"
#include "reporter/reporter.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/mpr_complex.h"
#include "coeffs/gnumpc.h"
#include "coeffs/longrat.h"
#include "coeffs/gnumpfl.h"
#include "coeffs/modulop.h"
#include "coeffs/shortfl.h"

Go to the source code of this file.

Functions

BOOLEAN ngcDBTest (number a, const char *f, const int l, const coeffs r)
 
static number ngcParameter (int i, const coeffs r)
 
static number ngcInit (long i, const coeffs r)
 
static long ngcInt (number &i, const coeffs r)
 
static BOOLEAN ngcIsZero (number a, const coeffs r)
 
static int ngcSize (number n, const coeffs R)
 
static void ngcDelete (number *a, const coeffs r)
 
static number ngcCopy (number a, const coeffs r)
 
static number ngcNeg (number a, const coeffs R)
 
static number ngcInvers (number a, const coeffs R)
 
static number ngcAdd (number a, number b, const coeffs R)
 
static void ngcInpAdd (number &a, number b, const coeffs R)
 
static number ngcSub (number a, number b, const coeffs R)
 
static number ngcMult (number a, number b, const coeffs R)
 
static void ngcInpMult (number &a, number b, const coeffs R)
 
static number ngcDiv (number a, number b, const coeffs r)
 
static void ngcPower (number x, int exp, number *u, const coeffs r)
 
static number ngcRePart (number a, const coeffs r)
 
static number ngcImPart (number a, const coeffs r)
 
static BOOLEAN ngcGreaterZero (number a, const coeffs r)
 
static BOOLEAN ngcGreater (number a, number b, const coeffs r)
 
static BOOLEAN ngcEqual (number a, number b, const coeffs r)
 
static BOOLEAN ngcIsOne (number a, const coeffs r)
 
static BOOLEAN ngcIsMOne (number a, const coeffs r)
 
static const char * ngcRead (const char *s, number *a, const coeffs r)
 
static void ngcWrite (number a, const coeffs r)
 
static BOOLEAN ngcCoeffIsEqual (const coeffs r, n_coeffType n, void *parameter)
 
static void ngcKillChar (coeffs r)
 
static char * ngcCoeffName (const coeffs r)
 
static void ngcCoeffWrite (const coeffs r, BOOLEAN)
 
static number ngcMapQ (number from, const coeffs aRing, const coeffs r)
 
static number ngcMapZ (number from, const coeffs aRing, const coeffs r)
 
static number ngcMapLongR (number from, const coeffs aRing, const coeffs r)
 
static number ngcMapR (number from, const coeffs aRing, const coeffs r)
 
static number ngcMapP (number from, const coeffs aRing, const coeffs r)
 
static number ngcCopyMap (number from, const coeffs aRing, const coeffs r)
 
static number ngcInitMPZ (mpz_t m, const coeffs)
 
static nMapFunc ngcSetMap (const coeffs src, const coeffs dst)
 
BOOLEAN ngcInitChar (coeffs n, void *parameter)
 Initialize r (n_long_C) More...
 
void ngcSetChar (const coeffs r)
 

Function Documentation

◆ ngcAdd()

static number ngcAdd ( number  a,
number  b,
const coeffs  R 
)
static

Definition at line 156 of file gnumpc.cc.

157 {
158  assume( getCoeffType(R) == n_long_C );
159 
160  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) + (*(gmp_complex*)b) );
161  return (number)r;
162 }
CanonicalForm b
Definition: cfModGcd.cc:4103
gmp_complex numbers based on
Definition: mpr_complex.h:179
@ n_long_C
complex floating point (GMP) numbers
Definition: coeffs.h:41
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
#define assume(x)
Definition: mod2.h:389
#define R
Definition: sirandom.c:27

◆ ngcCoeffIsEqual()

static BOOLEAN ngcCoeffIsEqual ( const coeffs  r,
n_coeffType  n,
void *  parameter 
)
static

Definition at line 392 of file gnumpc.cc.

393 {
394  if (n==n_long_C)
395  {
396  LongComplexInfo* p = (LongComplexInfo *)(parameter);
397 
398  if ((p==NULL)
399  && (SHORT_REAL_LENGTH==r->float_len)
400  && (SHORT_REAL_LENGTH==r->float_len2)
401  && (strcmp("i",n_ParameterNames(r)[0]) == 0)
402  )
403  return TRUE;
404  if ((p!=NULL) &&
405  (p->float_len == r->float_len) &&
406  (p->float_len2 == r->float_len2)
407  )
408  if (strcmp(p->par_name, n_ParameterNames(r)[0]) == 0)
409  return (TRUE);
410  }
411  return (FALSE);
412 }
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int p
Definition: cfModGcd.cc:4078
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:778
#define SHORT_REAL_LENGTH
Definition: numbers.h:57
#define NULL
Definition: omList.c:12

◆ ngcCoeffName()

static char* ngcCoeffName ( const coeffs  r)
static

Definition at line 427 of file gnumpc.cc.

428 {
429  STATIC_VAR char ngcCoeffName_buf[40];
430  const char *p=n_ParameterNames(r)[0];
431  sprintf(ngcCoeffName_buf,"complex,%d,%d,%s",r->float_len,r->float_len2,p);
432  return ngcCoeffName_buf;
433 }
#define STATIC_VAR
Definition: globaldefs.h:7

◆ ngcCoeffWrite()

static void ngcCoeffWrite ( const coeffs  r,
BOOLEAN   
)
static

Definition at line 435 of file gnumpc.cc.

436 {
437  Print("real[%s](complex:%d digits, additional %d digits)/(%s^2+1)",n_ParameterNames(r)[0],
438  r->float_len, r->float_len2, n_ParameterNames(r)[0]); /* long C */
439 }
#define Print
Definition: emacs.cc:80

◆ ngcCopy()

static number ngcCopy ( number  a,
const coeffs  r 
)
static

Definition at line 112 of file gnumpc.cc.

113 {
114  assume( getCoeffType(r) == n_long_C );
115 
116  gmp_complex* b= new gmp_complex( *(gmp_complex*)a );
117  return (number)b;
118 }

◆ ngcCopyMap()

static number ngcCopyMap ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 515 of file gnumpc.cc.

516 {
517  assume( getCoeffType(r) == n_long_C );
518  assume( getCoeffType(aRing) == n_long_C );
519 
520  gmp_complex* b = NULL;
521 
522  if ( from != NULL )
523  {
524  b = new gmp_complex( *(gmp_complex*)from );
525  }
526  return (number)b;
527 }

◆ ngcDBTest()

BOOLEAN ngcDBTest ( number  a,
const char *  f,
const int  l,
const coeffs  r 
)

Definition at line 32 of file gnumpc.cc.

33 {
34  assume( getCoeffType(r) == n_long_C );
35 
36  return TRUE;
37 }

◆ ngcDelete()

static void ngcDelete ( number *  a,
const coeffs  r 
)
static

Definition at line 98 of file gnumpc.cc.

99 {
100  assume( getCoeffType(r) == n_long_C );
101 
102  if ( *a != NULL )
103  {
104  delete *(gmp_complex**)a;
105  *a=NULL;
106  }
107 }

◆ ngcDiv()

static number ngcDiv ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 203 of file gnumpc.cc.

204 {
205  assume( getCoeffType(r) == n_long_C );
206 
207  if (((gmp_complex*)b)->isZero())
208  {
209  // a/0 = error
210  WerrorS(nDivBy0);
211  return (number)new gmp_complex( 0 );
212  }
213  gmp_complex* res = new gmp_complex( (*(gmp_complex*)a) / (*(gmp_complex*)b) );
214  return (number)res;
215 }
CanonicalForm res
Definition: facAbsFact.cc:60
bool isZero(const CFArray &A)
checks if entries of A are zero
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char *const nDivBy0
Definition: numbers.h:88

◆ ngcEqual()

static BOOLEAN ngcEqual ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 309 of file gnumpc.cc.

310 {
311  assume( getCoeffType(r) == n_long_C );
312 
313  gmp_complex *aa=(gmp_complex*)a;
314  gmp_complex *bb=(gmp_complex*)b;
315  return (*aa) == (*bb);
316 }

◆ ngcGreater()

static BOOLEAN ngcGreater ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 297 of file gnumpc.cc.

298 {
299  assume( getCoeffType(r) == n_long_C );
300 
301  gmp_complex *aa=(gmp_complex*)a;
302  gmp_complex *bb=(gmp_complex*)b;
303  return (*aa) > (*bb);
304 }

◆ ngcGreaterZero()

static BOOLEAN ngcGreaterZero ( number  a,
const coeffs  r 
)
static

Definition at line 284 of file gnumpc.cc.

285 {
286  assume( getCoeffType(r) == n_long_C );
287 
288  if ( ! ((gmp_complex*)a)->imag().isZero() )
289  return ( abs( *(gmp_complex*)a).sign() >= 0 );
290  else
291  return ( ((gmp_complex*)a)->real().sign() >= 0 );
292 }
Rational abs(const Rational &a)
Definition: GMPrat.cc:436
static int sign(int x)
Definition: ring.cc:3469

◆ ngcImPart()

static number ngcImPart ( number  a,
const coeffs  r 
)
static

Definition at line 273 of file gnumpc.cc.

274 {
275  assume( getCoeffType(r) == n_long_C );
276 
277  gmp_complex* n = new gmp_complex(((gmp_complex*)a)->imag());
278  return (number)n;
279 }

◆ ngcInit()

static number ngcInit ( long  i,
const coeffs  r 
)
static

Definition at line 54 of file gnumpc.cc.

55 {
56  assume( getCoeffType(r) == n_long_C );
57 
58  gmp_complex* n= new gmp_complex( (long)i, 0L );
59 
60  return (number)n;
61 }
int i
Definition: cfEzgcd.cc:132

◆ ngcInitChar()

BOOLEAN ngcInitChar ( coeffs  n,
void *  parameter 
)

Initialize r (n_long_C)

Definition at line 568 of file gnumpc.cc.

569 {
570  assume( getCoeffType(n) == n_long_C );
571  n->is_field=TRUE;
572  n->is_domain=TRUE;
573  n->rep=n_rep_gmp_complex;
574 
575  n->cfKillChar = ngcKillChar;
576  n->ch = 0;
577  n->cfCoeffName=ngcCoeffName;
578  n->cfCoeffWrite = ngcCoeffWrite;
579 
580  n->cfDelete = ngcDelete;
581  //n->cfNormalize=ndNormalize;
582  n->cfInit = ngcInit;
583  n->cfInitMPZ = ngcInitMPZ;
584  n->cfInt = ngcInt;
585  n->cfAdd = ngcAdd;
586  n->cfInpAdd = ngcInpAdd;
587  n->cfSub = ngcSub;
588  n->cfMult = ngcMult;
589  n->cfInpMult = ngcInpMult;
590  n->cfDiv = ngcDiv;
591  n->cfExactDiv= ngcDiv;
592  n->cfInpNeg = ngcNeg;
593  n->cfInvers = ngcInvers;
594  n->cfCopy = ngcCopy;
595  n->cfGreater = ngcGreater;
596  n->cfEqual = ngcEqual;
597  n->cfIsZero = ngcIsZero;
598  n->cfIsOne = ngcIsOne;
599  n->cfIsMOne = ngcIsMOne;
600  n->cfGreaterZero = ngcGreaterZero;
601 
602  n->cfWriteLong = ngcWrite;
603  n->cfWriteShort = ngcWrite;
604 
605  n->cfRead = ngcRead;
606  n->cfPower = ngcPower;
607  n->cfSetMap = ngcSetMap;
608  n->cfRePart = ngcRePart;
609  n->cfImPart = ngcImPart;
610  // cfSize = ndSize;
611 #ifdef LDEBUG
612  //n->cfDBTest = ndDBTest; // not yet implemented: ngcDBTest
613 #endif
614 
615  n->nCoeffIsEqual = ngcCoeffIsEqual;
616 
617  n->cfSetChar=ngcSetChar;
618 
619 /*
620  //r->cfInitChar=nlInitChar;
621  r->cfKillChar=NULL;
622 
623  r->cfMult = nlMult;
624  r->cfSub = nlSub;
625  r->cfAdd = nlAdd;
626  r->cfDiv = nlDiv;
627  r->cfIntMod= nlIntMod;
628  r->cfExactDiv= nlExactDiv;
629  r->cfInit = nlInit;
630  r->cfSize = nlSize;
631  r->cfInt = nlInt;
632 #ifdef HAVE_RINGS
633  r->cfDivComp = NULL; // only for ring stuff
634  r->cfIsUnit = NULL; // only for ring stuff
635  r->cfGetUnit = NULL; // only for ring stuff
636  r->cfExtGcd = NULL; // only for ring stuff
637 #endif
638  r->cfInpNeg = nlNeg;
639  r->cfInvers= nlInvers;
640  r->cfCopy = nl_Copy;
641  r->cfRePart = nl_Copy;
642  r->cfImPart = ndReturn0;
643  r->cfWriteLong = nlWrite;
644  r->cfRead = nlRead;
645  r->cfNormalize=nlNormalize;
646  r->cfGreater = nlGreater;
647 #ifdef HAVE_RINGS
648  r->cfDivBy = NULL; // only for ring stuff
649 #endif
650  r->cfEqual = nlEqual;
651  r->cfIsZero = nlIsZero;
652  r->cfIsOne = nlIsOne;
653  r->cfIsMOne = nlIsMOne;
654  r->cfGreaterZero = nlGreaterZero;
655  r->cfPower = nlPower;
656  r->cfGetDenom = nlGetDenom;
657  r->cfGetNumerator = nlGetNumerator;
658  r->cfGcd = nlGcd;
659  r->cfLcm = nlLcm;
660  r->cfDelete= nlDelete;
661  r->cfSetMap = nlSetMap;
662  r->cfName = ndName;
663  r->cfInpMult=nlInpMult;
664 #ifdef LDEBUG
665  // debug stuff
666  r->cfDBTest=nlDBTest;
667 #endif
668 
669  // the variables:
670  r->type = n_Q;
671  r->ch = 0;
672  r->has_simple_Alloc=FALSE;
673  r->has_simple_Inverse=FALSE;
674 */
675 
676  n->iNumberOfParameters = 1;
677  n->cfParameter = ngcParameter;
678 
679  char ** pParameterNames = (char **) omAlloc0(sizeof(char *));
680 
681  if( parameter != NULL)
682  {
683  LongComplexInfo* p = (LongComplexInfo*)parameter;
684  pParameterNames[0] = omStrDup(p->par_name);
685  // fix wrong parameters:
686  if (p->float_len<SHORT_REAL_LENGTH) p->float_len=SHORT_REAL_LENGTH;
687  n->float_len = p->float_len;
688  n->float_len2 = p->float_len2;
689 
690  } else // default values, just for testing!
691  {
692  pParameterNames[0] = omStrDup("i");
693  n->float_len = SHORT_REAL_LENGTH;
694  n->float_len2 = SHORT_REAL_LENGTH;
695  }
696 
697  assume( pParameterNames != NULL );
698  assume( pParameterNames[0] != NULL );
699 
700  n->pParameterNames = (const char**)pParameterNames;
701 
702  // NOTE: n->complex_parameter was replaced by n_ParameterNames(n)[0]
703  // TODO: nfKillChar MUST destroy n->pParameterNames[0] (0-term. string) && n->pParameterNames (array of size 1)
704 
705  return FALSE;
706 }
@ n_rep_gmp_complex
(gmp_complex), see gnumpc.h
Definition: coeffs.h:118
static void ngcKillChar(coeffs r)
Definition: gnumpc.cc:414
static number ngcImPart(number a, const coeffs r)
Definition: gnumpc.cc:273
static number ngcDiv(number a, number b, const coeffs r)
Definition: gnumpc.cc:203
static void ngcDelete(number *a, const coeffs r)
Definition: gnumpc.cc:98
static void ngcInpMult(number &a, number b, const coeffs R)
Definition: gnumpc.cc:193
static number ngcSub(number a, number b, const coeffs R)
Definition: gnumpc.cc:174
static const char * ngcRead(const char *s, number *a, const coeffs r)
Definition: gnumpc.cc:343
static number ngcCopy(number a, const coeffs r)
Definition: gnumpc.cc:112
static number ngcInvers(number a, const coeffs R)
Definition: gnumpc.cc:136
static number ngcInitMPZ(mpz_t m, const coeffs)
Definition: gnumpc.cc:529
void ngcSetChar(const coeffs r)
Definition: gnumpc.cc:708
static void ngcPower(number x, int exp, number *u, const coeffs r)
Definition: gnumpc.cc:220
static number ngcAdd(number a, number b, const coeffs R)
Definition: gnumpc.cc:156
static nMapFunc ngcSetMap(const coeffs src, const coeffs dst)
Definition: gnumpc.cc:537
static BOOLEAN ngcIsMOne(number a, const coeffs r)
Definition: gnumpc.cc:332
static BOOLEAN ngcCoeffIsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: gnumpc.cc:392
static BOOLEAN ngcGreaterZero(number a, const coeffs r)
Definition: gnumpc.cc:284
static number ngcInit(long i, const coeffs r)
Definition: gnumpc.cc:54
static number ngcRePart(number a, const coeffs r)
Definition: gnumpc.cc:265
static void ngcCoeffWrite(const coeffs r, BOOLEAN)
Definition: gnumpc.cc:435
static BOOLEAN ngcGreater(number a, number b, const coeffs r)
Definition: gnumpc.cc:297
static number ngcParameter(int i, const coeffs r)
Definition: gnumpc.cc:40
static void ngcWrite(number a, const coeffs r)
Definition: gnumpc.cc:376
static number ngcNeg(number a, const coeffs R)
Definition: gnumpc.cc:124
static BOOLEAN ngcIsZero(number a, const coeffs r)
Definition: gnumpc.cc:73
static number ngcMult(number a, number b, const coeffs R)
Definition: gnumpc.cc:185
static void ngcInpAdd(number &a, number b, const coeffs R)
Definition: gnumpc.cc:164
static BOOLEAN ngcIsOne(number a, const coeffs r)
Definition: gnumpc.cc:321
static long ngcInt(number &i, const coeffs r)
Definition: gnumpc.cc:66
static char * ngcCoeffName(const coeffs r)
Definition: gnumpc.cc:427
static BOOLEAN ngcEqual(number a, number b, const coeffs r)
Definition: gnumpc.cc:309
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ ngcInitMPZ()

static number ngcInitMPZ ( mpz_t  m,
const  coeffs 
)
static

Definition at line 529 of file gnumpc.cc.

530 {
531  gmp_float mm(m);
532  gmp_complex* res = new gmp_complex(mm);
533  return (number)res;
534 }
int m
Definition: cfEzgcd.cc:128

◆ ngcInpAdd()

static void ngcInpAdd ( number &  a,
number  b,
const coeffs  R 
)
static

Definition at line 164 of file gnumpc.cc.

165 {
166  assume( getCoeffType(R) == n_long_C );
167 
168  (*(gmp_complex*)a) += (*(gmp_complex*)b);
169 }

◆ ngcInpMult()

static void ngcInpMult ( number &  a,
number  b,
const coeffs  R 
)
static

Definition at line 193 of file gnumpc.cc.

194 {
195  assume( getCoeffType(R) == n_long_C );
196 
197  (*(gmp_complex*)a) *= (*(gmp_complex*)b);
198 }

◆ ngcInt()

static long ngcInt ( number &  i,
const coeffs  r 
)
static

Definition at line 66 of file gnumpc.cc.

67 {
68  assume( getCoeffType(r) == n_long_C );
69 
70  return ((gmp_complex*)i)->real();
71 }

◆ ngcInvers()

static number ngcInvers ( number  a,
const coeffs  R 
)
static

Definition at line 136 of file gnumpc.cc.

137 {
138  assume( getCoeffType(R) == n_long_C );
139 
140  gmp_complex* r = NULL;
141  if (((gmp_complex*)a)->isZero())
142  {
143  WerrorS(nDivBy0);
144  r = new gmp_complex( 0 );
145  }
146  else
147  {
148  r = new gmp_complex( (gmp_complex)1 / (*(gmp_complex*)a) );
149  }
150  return (number)r;
151 }

◆ ngcIsMOne()

static BOOLEAN ngcIsMOne ( number  a,
const coeffs  r 
)
static

Definition at line 332 of file gnumpc.cc.

333 {
334  assume( getCoeffType(r) == n_long_C );
335 
336  return (((gmp_complex*)a)->real().isMOne() && ((gmp_complex*)a)->imag().isZero());
337  //return (((gmp_complex*)a)->real().isMOne());
338 }

◆ ngcIsOne()

static BOOLEAN ngcIsOne ( number  a,
const coeffs  r 
)
static

Definition at line 321 of file gnumpc.cc.

322 {
323  assume( getCoeffType(r) == n_long_C );
324 
325  return (((gmp_complex*)a)->real().isOne() && ((gmp_complex*)a)->imag().isZero());
326  //return (((gmp_complex*)a)->real().isOne());
327 }

◆ ngcIsZero()

static BOOLEAN ngcIsZero ( number  a,
const coeffs  r 
)
static

Definition at line 73 of file gnumpc.cc.

74 {
75  assume( getCoeffType(r) == n_long_C );
76 
77  return ( ((gmp_complex*)a)->real().isZero() && ((gmp_complex*)a)->imag().isZero());
78 }

◆ ngcKillChar()

static void ngcKillChar ( coeffs  r)
static

Definition at line 414 of file gnumpc.cc.

415 {
416  char** p = (char**)n_ParameterNames(r);
417 
418  const int P = n_NumberOfParameters(r);
419 
420  for( int i = 1; i <= P; i++ )
421  if (p[i-1] != NULL)
422  omFree( (ADDRESS)p[i-1] );
423 
424  omFreeSize((ADDRESS)p, P * sizeof(char*));
425 }
void * ADDRESS
Definition: auxiliary.h:119
static FORCE_INLINE int n_NumberOfParameters(const coeffs r)
Returns the number of parameters.
Definition: coeffs.h:774
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omFree(addr)
Definition: omAllocDecl.h:261

◆ ngcMapLongR()

static number ngcMapLongR ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 476 of file gnumpc.cc.

477 {
478  assume( getCoeffType(r) == n_long_C );
479  assume( getCoeffType(aRing) == n_long_R );
480 
481  if ( from != NULL )
482  {
483  gmp_complex *res=new gmp_complex(*((gmp_float *)from));
484  return (number)res;
485  }
486  else
487  return NULL;
488 }
@ n_long_R
real floating point (GMP) numbers
Definition: coeffs.h:33

◆ ngcMapP()

static number ngcMapP ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 504 of file gnumpc.cc.

505 {
506  assume( getCoeffType(r) == n_long_C );
507  assume( getCoeffType(aRing) == n_Zp );
508 
509  if ( from != NULL )
510  return ngcInit(npInt(from, aRing), r); // FIXME? TODO? // extern int npInt (number &n, const coeffs r);
511  else
512  return NULL;
513 }
@ n_Zp
\F{p < 2^31}
Definition: coeffs.h:29
long npInt(number &n, const coeffs r)
Definition: modulop.cc:85

◆ ngcMapQ()

static number ngcMapQ ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 441 of file gnumpc.cc.

442 {
443  assume( getCoeffType(r) == n_long_C );
444  assume( aRing->rep == n_rep_gap_rat);
445 
446  if ( from != NULL )
447  {
449  return (number)res;
450  }
451  else
452  return NULL;
453 }
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
gmp_float numberFieldToFloat(number num, int cf)
Definition: mpr_complex.cc:438
#define QTOF
Definition: mpr_complex.h:19

◆ ngcMapR()

static number ngcMapR ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 490 of file gnumpc.cc.

491 {
492  assume( getCoeffType(r) == n_long_C );
493  assume( getCoeffType(aRing) == n_R );
494 
495  if ( from != NULL )
496  {
497  gmp_complex *res=new gmp_complex((double)nrFloat(from));
498  return (number)res;
499  }
500  else
501  return NULL;
502 }
@ n_R
single prescision (6,6) real numbers
Definition: coeffs.h:31
SI_FLOAT nrFloat(number n)
Converts a n_R number into a float. Needed by Maps.
Definition: shortfl.cc:48

◆ ngcMapZ()

static number ngcMapZ ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 455 of file gnumpc.cc.

456 {
457  assume( getCoeffType(r) == n_long_C );
458  assume( aRing->rep == n_rep_gap_gmp);
459 
460  if ( from != NULL )
461  {
462  if (SR_HDL(from) & SR_INT)
463  {
464  gmp_float f_i= gmp_float(SR_TO_INT(from));
465  gmp_complex *res=new gmp_complex(f_i);
466  return (number)res;
467  }
468  gmp_float f_i=(mpz_ptr)from;
469  gmp_complex *res=new gmp_complex(f_i);
470  return (number)res;
471  }
472  else
473  return NULL;
474 }
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:112
#define SR_INT
Definition: longrat.h:67
#define SR_TO_INT(SR)
Definition: longrat.h:69
#define SR_HDL(A)
Definition: tgb.cc:35

◆ ngcMult()

static number ngcMult ( number  a,
number  b,
const coeffs  R 
)
static

Definition at line 185 of file gnumpc.cc.

186 {
187  assume( getCoeffType(R) == n_long_C );
188 
189  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) * (*(gmp_complex*)b) );
190  return (number)r;
191 }

◆ ngcNeg()

static number ngcNeg ( number  a,
const coeffs  R 
)
static

Definition at line 124 of file gnumpc.cc.

125 {
126  assume( getCoeffType(R) == n_long_C );
127 
128  gmp_complex* r=(gmp_complex*)a;
129  (*r).neg();
130  return (number)a;
131 }
gmp_complex & neg()
Definition: mpr_complex.cc:660

◆ ngcParameter()

static number ngcParameter ( int  i,
const coeffs  r 
)
static

Definition at line 40 of file gnumpc.cc.

41 {
42  assume( getCoeffType(r) == n_long_C );
43  assume(i==1);
44 
45  if( i == 1 )
46  return (number)(new gmp_complex( 0L, 1L ));
47 
48  return NULL; // new gmp_complex( ) // 0?
49 }

◆ ngcPower()

static void ngcPower ( number  x,
int  exp,
number *  u,
const coeffs  r 
)
static

Definition at line 220 of file gnumpc.cc.

221 {
222  assume( getCoeffType(r) == n_long_C );
223 
224  if ( exp == 0 )
225  {
226  gmp_complex* n = new gmp_complex(1);
227  *u=(number)n;
228  return;
229  }
230  else if ( exp == 1 )
231  {
232  n_New(u, r);
233  gmp_complex* n = new gmp_complex();
234  *n= *(gmp_complex*)x;
235  *u=(number)n;
236  return;
237  }
238  else if (exp == 2)
239  {
240  n_New(u, r);
241  gmp_complex* n = new gmp_complex();
242  *n= *(gmp_complex*)x;
243  *u=(number)n;
244  *(gmp_complex*)(*u) *= *(gmp_complex*)n;
245  return;
246  }
247  if ( (exp & 1) == 1 )
248  {
249  ngcPower(x,exp-1,u, r);
250  gmp_complex *n = new gmp_complex();
251  *n=*(gmp_complex*)x;
252  *(gmp_complex*)(*u) *= *(gmp_complex*)n;
253  delete n;
254  }
255  else
256  {
257  number w;
258  n_New(&w, r);
259  ngcPower(x,exp/2,&w, r);
260  ngcPower(w,2,u, r);
261  n_Delete(&w, r);
262  }
263 }
Variable x
Definition: cfModGcd.cc:4082
#define n_New(n, r)
Definition: coeffs.h:440
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
const CanonicalForm & w
Definition: facAbsFact.cc:51
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357

◆ ngcRead()

static const char* ngcRead ( const char *  s,
number *  a,
const coeffs  r 
)
static

Definition at line 343 of file gnumpc.cc.

344 {
345  assume( getCoeffType(r) == n_long_C );
346  const char * const complex_parameter = n_ParameterNames(r)[0];
347  assume( complex_parameter != NULL );
348  const int N = strlen(complex_parameter);
349 
350  if ((*s >= '0') && (*s <= '9'))
351  {
352  gmp_float *re=NULL;
353  s=ngfRead(s,(number *)&re, r); // FIXME? TODO? // extern const char * ngfRead (const char *s, number *a, const coeffs r);
354  gmp_complex *aa=new gmp_complex(*re);
355  *a=(number)aa;
356  delete re;
357  }
358  else if (strncmp(s, complex_parameter, N)==0)
359  {
360  s += N;
361  gmp_complex *aa=new gmp_complex(0L,1L);
362  *a=(number)aa;
363  }
364  else
365  {
366  *a=(number) new gmp_complex(1L);
367  }
368  return s;
369 }
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
const CanonicalForm int s
Definition: facAbsFact.cc:51
const char * ngfRead(const char *s, number *a, const coeffs r)
Definition: gnumpfl.cc:326

◆ ngcRePart()

static number ngcRePart ( number  a,
const coeffs  r 
)
static

Definition at line 265 of file gnumpc.cc.

266 {
267  assume( getCoeffType(r) == n_long_C );
268 
269  gmp_complex* n = new gmp_complex(((gmp_complex*)a)->real());
270  return (number)n;
271 }

◆ ngcSetChar()

void ngcSetChar ( const coeffs  r)

Definition at line 708 of file gnumpc.cc.

709 {
710  setGMPFloatDigits(r->float_len, r->float_len2);
711 }
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...
Definition: mpr_complex.cc:60

◆ ngcSetMap()

static nMapFunc ngcSetMap ( const coeffs  src,
const coeffs  dst 
)
static

Definition at line 537 of file gnumpc.cc.

538 {
539  assume( getCoeffType(dst) == n_long_C );
540 
541  if (src->rep==n_rep_gap_rat) /* Q, Z*/
542  {
543  return ngcMapQ;
544  }
545  if (src->rep==n_rep_gap_gmp) /* Z */
546  {
547  return ngcMapZ;
548  }
549  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
550  {
551  return ngcMapLongR;
552  }
553  if ((src->rep==n_rep_gmp_complex) && nCoeff_is_long_C(src))
554  {
555  return ngcCopyMap;
556  }
557  if ((src->rep==n_rep_float) && nCoeff_is_R(src))
558  {
559  return ngcMapR;
560  }
561  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
562  {
563  return ngcMapP;
564  }
565  return NULL;
566 }
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:891
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:800
@ n_rep_float
(float), see shortfl.h
Definition: coeffs.h:116
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
@ n_rep_gmp_float
(gmp_float), see
Definition: coeffs.h:117
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:836
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition: coeffs.h:894
static number ngcMapQ(number from, const coeffs aRing, const coeffs r)
Definition: gnumpc.cc:441
static number ngcMapP(number from, const coeffs aRing, const coeffs r)
Definition: gnumpc.cc:504
static number ngcCopyMap(number from, const coeffs aRing, const coeffs r)
Definition: gnumpc.cc:515
static number ngcMapZ(number from, const coeffs aRing, const coeffs r)
Definition: gnumpc.cc:455
static number ngcMapLongR(number from, const coeffs aRing, const coeffs r)
Definition: gnumpc.cc:476
static number ngcMapR(number from, const coeffs aRing, const coeffs r)
Definition: gnumpc.cc:490

◆ ngcSize()

static int ngcSize ( number  n,
const coeffs  R 
)
static

Definition at line 80 of file gnumpc.cc.

81 {
82  int r = (int)((gmp_complex*)n)->real();
83  if (r < 0) r = -r;
84  int i = (int)((gmp_complex*)n)->imag();
85  if (i < 0) i = -i;
86  int oneNorm = r + i;
87  /* basically return the 1-norm of n;
88  only if this happens to be zero although n != 0,
89  return 1;
90  (this code ensures that zero has the size zero) */
91  if ((oneNorm == 0.0) & (ngcIsZero(n,R) == FALSE)) oneNorm = 1;
92  return oneNorm;
93 }
static CanonicalForm oneNorm(const CanonicalForm &F)

◆ ngcSub()

static number ngcSub ( number  a,
number  b,
const coeffs  R 
)
static

Definition at line 174 of file gnumpc.cc.

175 {
176  assume( getCoeffType(R) == n_long_C );
177 
178  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) - (*(gmp_complex*)b) );
179  return (number)r;
180 }

◆ ngcWrite()

static void ngcWrite ( number  a,
const coeffs  r 
)
static

Definition at line 376 of file gnumpc.cc.

377 {
378  assume( getCoeffType(r) == n_long_C );
379 
380  if (a==NULL)
381  StringAppendS("0");
382  else
383  {
384  char *out;
385  out= complexToStr(*(gmp_complex*)a, r->float_len, r);
386  StringAppendS(out);
387  // omFreeSize((void *)out, (strlen(out)+1)* sizeof(char) );
388  omFree( (void *)out );
389  }
390 }
char * complexToStr(gmp_complex &c, const unsigned int oprec, const coeffs src)
Definition: mpr_complex.cc:704
void StringAppendS(const char *st)
Definition: reporter.cc:107