source: git/libpolys/coeffs/gnumpc.cc @ 45cc512

jengelh-datetimespielwiese
Last change on this file since 45cc512 was 45cc512, checked in by Hans Schoenemann <hannes@…>, 9 years ago
chg: rCharstr is now a wrapper for r->cf->cfCoeffString fixes also: charstr for integer,2,3
  • Property mode set to 100644
File size: 15.3 KB
RevLine 
[35aab3]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: computations with GMP complex floating-point numbers
6*
7* ngc == number gnu complex
8*/
9
[16f511]10#ifdef HAVE_CONFIG_H
[ba5e9e]11#include "libpolysconfig.h"
[16f511]12#endif /* HAVE_CONFIG_H */
[c3d175]13
[7fee876]14#include <omalloc/omalloc.h>
15
16#include <misc/auxiliary.h>
17#include <misc/mylimits.h>
18
19#include <reporter/reporter.h>
20
[2d805a]21#include <coeffs/coeffs.h>
22#include <coeffs/numbers.h>
[7fee876]23
[2d805a]24#include <coeffs/longrat.h>
25#include <coeffs/modulop.h>
[7fee876]26
[2d805a]27#include <coeffs/gnumpc.h>
28#include <coeffs/gnumpfl.h>
[7fee876]29#include <coeffs/shortfl.h>
30
[2d805a]31#include <coeffs/mpr_complex.h>
[35aab3]32
33
[7fee876]34/// Get a mapping function from src into the domain of this type: long_C!
35nMapFunc  ngcSetMap(const coeffs src, const coeffs dst);
36
37number ngcMapQ(number from, const coeffs r, const coeffs aRing);
38
39void ngcSetChar(const coeffs r);
40
41// Private interface should be hidden!!!
42
43/// Note: MAY NOT WORK AS EXPECTED!
44BOOLEAN  ngcGreaterZero(number za, const coeffs r); 
45BOOLEAN  ngcGreater(number a, number b, const coeffs r);
46BOOLEAN  ngcEqual(number a, number b, const coeffs r);
47BOOLEAN  ngcIsOne(number a, const coeffs r);
48BOOLEAN  ngcIsMOne(number a, const coeffs r);
49BOOLEAN  ngcIsZero(number za, const coeffs r);
50number   ngcInit(long i, const coeffs r);
51int      ngcInt(number &n, const coeffs r);
52number   ngcNeg(number za, const coeffs r);
53number   ngcInvers(number a, const coeffs r);
54number   ngcParameter(int i, const coeffs r);
55number   ngcAdd(number la, number li, const coeffs r);
56number   ngcSub(number la, number li, const coeffs r);
57number   ngcMult(number a, number b, const coeffs r);
58number   ngcDiv(number a, number b, const coeffs r);
59void     ngcPower(number x, int exp, number *lu, const coeffs r);
60number   ngcCopy(number a, const coeffs r);
61number   ngc_Copy(number a, coeffs r);
62const char * ngcRead (const char *s, number *a, const coeffs r);
63void     ngcWrite(number &a, const coeffs r);
64number   ngcRePart(number a, const coeffs r);
65number   ngcImPart(number a, const coeffs r);
66
67void     ngcDelete(number *a, const coeffs r);
68void     ngcCoeffWrite(const coeffs r, BOOLEAN details);
69
70#ifdef LDEBUG
71BOOLEAN  ngcDBTest(number a, const char *f, const int l, const coeffs r);
72#endif
73
74
75// Why is this here? who needs it?
76// number ngcMapQ(number from, const coeffs r, const coeffs aRing);
[3aae0e]77
[51d835]78/// Our Type!
79static const n_coeffType ID = n_long_C;
80
[3aae0e]81
[94b759]82#ifdef LDEBUG
83// not yet implemented
[9bb5457]84BOOLEAN ngcDBTest(number, const char *, const int, const coeffs r)
[94b759]85{
86  assume( getCoeffType(r) == ID );
87
88  return TRUE;
89}
90#endif
91
[7fee876]92number   ngcParameter(int i, const coeffs r)
[35aab3]93{
[94b759]94  assume( getCoeffType(r) == ID );
[121fd9]95  assume(i==1);
[94b759]96
[7fee876]97  if( i == 1 )
98    return (number)(new gmp_complex( (long)0, (long)1 ));
99
100  return NULL; // new gmp_complex( )  // 0?
[35aab3]101}
102
103/*2
104* n := i
105*/
[2f3764]106number ngcInit (long i, const coeffs r)
[35aab3]107{
[94b759]108  assume( getCoeffType(r) == ID );
[9bb5457]109
[78e67e]110  gmp_complex* n= new gmp_complex( (long)i, (long)0 );
[9bb5457]111
[35aab3]112  return (number)n;
113}
114
115/*2
116* convert number to int
117*/
[7d90aa]118int ngcInt(number &i, const coeffs r)
[35aab3]119{
[94b759]120  assume( getCoeffType(r) == ID );
[9bb5457]121
[35aab3]122  return (int)((gmp_complex*)i)->real();
123}
124
[95d8df]125int ngcSize(number n, const coeffs R)
[12cca3]126{
127  int r = (int)((gmp_complex*)n)->real();
128  if (r < 0) r = -r;
129  int i = (int)((gmp_complex*)n)->imag();
130  if (i < 0) i = -i;
131  int oneNorm = r + i;
132  /* basically return the 1-norm of n;
133     only if this happens to be zero although n != 0,
134     return 1;
135     (this code ensures that zero has the size zero) */
[95d8df]136  if ((oneNorm == 0.0) & (ngcIsZero(n,R) == FALSE)) oneNorm = 1;
[12cca3]137  return oneNorm;
138}
139
[35aab3]140/*2
141* delete a
142*/
[7d90aa]143void ngcDelete (number * a, const coeffs r)
[35aab3]144{
[94b759]145  assume( getCoeffType(r) == ID );
146
[7c961ba]147  if ( *a != NULL )
148  {
[35aab3]149    delete *(gmp_complex**)a;
150    *a=NULL;
151  }
152}
153
154/*2
[8cb8e1]155 * copy a to b
[35aab3]156*/
[94b759]157number ngcCopy(number a, const coeffs r)
[35aab3]158{
[94b759]159  assume( getCoeffType(r) == ID );
[9bb5457]160
[78e67e]161  gmp_complex* b= new gmp_complex( *(gmp_complex*)a );
[35aab3]162  return (number)b;
163}
[94b759]164
[35aab3]165
166/*2
167* za:= - za
168*/
[94b759]169number ngcNeg (number a, const coeffs R)
[35aab3]170{
[94b759]171  assume( getCoeffType(R) == ID );
172
[0f4db3]173  gmp_complex* r=(gmp_complex*)a;
[95d8df]174  (*r).neg();
[35aab3]175  return (number)a;
176}
177
178/*
179* 1/a
180*/
[94b759]181number ngcInvers(number a, const coeffs R)
[35aab3]182{
[94b759]183  assume( getCoeffType(R) == ID );
184
[b7e838]185  gmp_complex* r = NULL;
[78e67e]186  if (((gmp_complex*)a)->isZero())
[35aab3]187  {
[b7e838]188    WerrorS(nDivBy0);
[35aab3]189  }
190  else
191  {
[95d8df]192    r = new gmp_complex( (gmp_complex)1 / (*(gmp_complex*)a) );
[35aab3]193  }
[95d8df]194  return (number)r;
[35aab3]195}
196
197/*2
198* u:= a + b
199*/
[94b759]200number ngcAdd (number a, number b, const coeffs R)
[35aab3]201{
[94b759]202  assume( getCoeffType(R) == ID );
203
[78e67e]204  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) + (*(gmp_complex*)b) );
[35aab3]205  return (number)r;
206}
207
208/*2
209* u:= a - b
210*/
[8cb8e1]211number ngcSub (number a, number b, const coeffs R)
[35aab3]212{
[94b759]213  assume( getCoeffType(R) == ID );
214
[78e67e]215  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) - (*(gmp_complex*)b) );
[35aab3]216  return (number)r;
217}
218
219/*2
220* u := a * b
221*/
[94b759]222number ngcMult (number a, number b, const coeffs R)
[35aab3]223{
[94b759]224  assume( getCoeffType(R) == ID );
[9bb5457]225
[78e67e]226  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) * (*(gmp_complex*)b) );
[35aab3]227  return (number)r;
228}
229
230/*2
231* u := a / b
232*/
[94b759]233number ngcDiv (number a, number b, const coeffs r)
[35aab3]234{
[94b759]235  assume( getCoeffType(r) == ID );
236
[78e67e]237  if (((gmp_complex*)b)->isZero())
[35aab3]238  {
[b7e838]239    // a/0 = error
240    WerrorS(nDivBy0);
[35aab3]241    return NULL;
242  }
[94b759]243  gmp_complex* res = new gmp_complex( (*(gmp_complex*)a) / (*(gmp_complex*)b) );
244  return (number)res;
[35aab3]245}
246
247/*2
248* u:= x ^ exp
249*/
[94b759]250void ngcPower ( number x, int exp, number * u, const coeffs r)
[35aab3]251{
[94b759]252  assume( getCoeffType(r) == ID );
253
[35aab3]254  if ( exp == 0 )
255  {
256    gmp_complex* n = new gmp_complex(1);
257    *u=(number)n;
258    return;
259  }
[5fe545]260  else if ( exp == 1 )
[35aab3]261  {
[94b759]262    n_New(u, r);
[78e67e]263    gmp_complex* n = new gmp_complex();
264    *n= *(gmp_complex*)x;
265    *u=(number)n;
[35aab3]266    return;
267  }
[5fe545]268  else if (exp == 2)
269  {
[94b759]270    n_New(u, r);
[78e67e]271    gmp_complex* n = new gmp_complex();
272    *n= *(gmp_complex*)x;
273    *u=(number)n;
274    *(gmp_complex*)(*u) *= *(gmp_complex*)n;
[5fe545]275    return;
276  }
[039016]277  if ( (exp & 1) == 1 )
[5fe545]278  {
[94b759]279    ngcPower(x,exp-1,u, r);
280    gmp_complex *n = new gmp_complex();
[5fe545]281    *n=*(gmp_complex*)x;
282    *(gmp_complex*)(*u) *= *(gmp_complex*)n;
283    delete n;
284  }
285  else
286  {
287    number w;
[94b759]288    n_New(&w, r);
289    ngcPower(x,exp/2,&w, r);
290    ngcPower(w,2,u, r);
291    n_Delete(&w, r);
[5fe545]292  }
[35aab3]293}
294
[94b759]295BOOLEAN ngcIsZero (number a, const coeffs r)
[35aab3]296{
[94b759]297  assume( getCoeffType(r) == ID );
298
[35aab3]299  return ( ((gmp_complex*)a)->real().isZero() && ((gmp_complex*)a)->imag().isZero());
300}
301
[94b759]302number ngcRePart(number a, const coeffs r)
[35aab3]303{
[94b759]304  assume( getCoeffType(r) == ID );
305
[35aab3]306  gmp_complex* n = new gmp_complex(((gmp_complex*)a)->real());
307  return (number)n;
308}
309
[94b759]310number ngcImPart(number a, const coeffs r)
[35aab3]311{
[94b759]312  assume( getCoeffType(r) == ID );
313
[35aab3]314  gmp_complex* n = new gmp_complex(((gmp_complex*)a)->imag());
315  return (number)n;
316}
317
318/*2
319* za >= 0 ?
320*/
[94b759]321BOOLEAN ngcGreaterZero (number a, const coeffs r)
[35aab3]322{
[94b759]323  assume( getCoeffType(r) == ID );
324
[35aab3]325  if ( ! ((gmp_complex*)a)->imag().isZero() )
326    return ( abs( *(gmp_complex*)a).sign() >= 0 );
327  else
328    return ( ((gmp_complex*)a)->real().sign() >= 0 );
329}
330
331/*2
332* a > b ?
333*/
[94b759]334BOOLEAN ngcGreater (number a, number b, const coeffs r)
[35aab3]335{
[94b759]336  assume( getCoeffType(r) == ID );
337
[890d63b]338  gmp_complex *aa=(gmp_complex*)a;
339  gmp_complex *bb=(gmp_complex*)b;
340  return (*aa) > (*bb);
[35aab3]341}
342
343/*2
344* a = b ?
345*/
[94b759]346BOOLEAN ngcEqual (number a, number b, const coeffs r)
[35aab3]347{
[94b759]348  assume( getCoeffType(r) == ID );
349
[890d63b]350  gmp_complex *aa=(gmp_complex*)a;
351  gmp_complex *bb=(gmp_complex*)b;
352  return (*aa) == (*bb);
[35aab3]353}
354
355/*2
356* a == 1 ?
357*/
[94b759]358BOOLEAN ngcIsOne (number a, const coeffs r)
[35aab3]359{
[94b759]360  assume( getCoeffType(r) == ID );
361
[78e67e]362  return (((gmp_complex*)a)->real().isOne() && ((gmp_complex*)a)->imag().isZero());
363  //return (((gmp_complex*)a)->real().isOne());
[35aab3]364}
365
366/*2
367* a == -1 ?
368*/
[94b759]369BOOLEAN ngcIsMOne (number a, const coeffs r)
[35aab3]370{
[94b759]371  assume( getCoeffType(r) == ID );
372
[78e67e]373  return (((gmp_complex*)a)->real().isMOne() && ((gmp_complex*)a)->imag().isZero());
374  //return (((gmp_complex*)a)->real().isMOne());
[35aab3]375}
376
377/*2
378* extracts the number a from s, returns the rest
379*/
[94b759]380const char * ngcRead (const char * s, number * a, const coeffs r)
[35aab3]381{
[94b759]382  assume( getCoeffType(r) == ID );
[7fee876]383  const char * const complex_parameter = n_ParameterNames(r)[0];
384  assume( complex_parameter != NULL );
385  const int N = strlen(complex_parameter);
[bfa04e]386
[35aab3]387  if ((*s >= '0') && (*s <= '9'))
388  {
389    gmp_float *re=NULL;
[94b759]390    s=ngfRead(s,(number *)&re, r);
[35aab3]391    gmp_complex *aa=new gmp_complex(*re);
392    *a=(number)aa;
393    delete re;
394  }
[7fee876]395  else if (strncmp(s, complex_parameter, N)==0)
[35aab3]396  {
[7fee876]397    s += N;
[35aab3]398    gmp_complex *aa=new gmp_complex((long)0,(long)1);
399    *a=(number)aa;
400  }
401  else
402  {
403    *a=(number) new gmp_complex((long)1);
404  }
405  return s;
406}
407
[94b759]408
409
[35aab3]410/*2
411* write a floating point number
412*/
[7d90aa]413void ngcWrite (number &a, const coeffs r)
[35aab3]414{
[94b759]415  assume( getCoeffType(r) == ID );
416
417  extern size_t gmp_output_digits; /// comes from mpr_complex.cc
418
[35aab3]419  if (a==NULL)
[e53182]420    StringAppendS("0");
[35aab3]421  else
422  {
423    char *out;
[ac5686]424    out= complexToStr(*(gmp_complex*)a, gmp_output_digits, r);
[e53182]425    StringAppendS(out);
[7d90aa]426    //    omFreeSize((void *)out, (strlen(out)+1)* sizeof(char) );
427    omFree( (void *)out );
[35aab3]428  }
429}
430
[32cc7e]431BOOLEAN ngcCoeffIsEqual (const coeffs r, n_coeffType n, void * parameter)
432{
[47ab5b]433  if (n==ID)
434  {
[32cc7e]435    LongComplexInfo* p = (LongComplexInfo *)(parameter);
[47ab5b]436   
437    if (
438        (p->float_len == r->float_len) &&
439        (p->float_len2 == r->float_len2)
440       )
[7fee876]441      if (strcmp(p->par_name, n_ParameterNames(r)[0]) == 0)
[47ab5b]442        return (TRUE);
[32cc7e]443  }
[47ab5b]444  return (FALSE);
[32cc7e]445}
446
[7fee876]447static void ngcKillChar(coeffs r)
448{
449  char** p = (char**)n_ParameterNames(r);
450
451  const int P = n_NumberOfParameters(r);
452
453  for( int i = 1; i <= P; i++ )
454    if (p[i-1] != NULL) 
455      omFree( (ADDRESS)p[i-1] );
456
457  omFreeSize((ADDRESS)p, P * sizeof(char*)); 
458}
459
[45cc512]460static char* ngcCoeffString(const coeffs r)
461{
462  const char *p=n_ParameterNames(r)[0];
463  char *s=(char*)omAlloc(21+strlen(p));
464  sprintf(s,"complex,%d,%s",r->float_len,p);
465  return s;
466}
467
[32cc7e]468BOOLEAN ngcInitChar(coeffs n, void* parameter)
[51d835]469{
470  assume( getCoeffType(n) == ID );
[32cc7e]471
[7fee876]472  n->cfKillChar = ngcKillChar;
[73a9ffb]473  n->ch = 0;
[45cc512]474  n->cfCoeffString=ngcCoeffString;
[51d835]475
476  n->cfDelete  = ngcDelete;
[7bbbef]477  n->cfNormalize=ndNormalize;
[51d835]478  n->cfInit   = ngcInit;
[7bbbef]479  n->cfInt    = ngcInt;
480  n->cfAdd     = ngcAdd;
481  n->cfSub     = ngcSub;
482  n->cfMult    = ngcMult;
483  n->cfDiv     = ngcDiv;
484  n->cfExactDiv= ngcDiv;
485  n->cfNeg     = ngcNeg;
486  n->cfInvers  = ngcInvers;
[51d835]487  n->cfCopy   = ngcCopy;
[7bbbef]488  n->cfGreater = ngcGreater;
489  n->cfEqual   = ngcEqual;
490  n->cfIsZero  = ngcIsZero;
491  n->cfIsOne   = ngcIsOne;
492  n->cfIsMOne  = ngcIsMOne;
493  n->cfGreaterZero = ngcGreaterZero;
[ce1f78]494
495  n->cfWriteLong  = ngcWrite;
496  n->cfWriteShort = ngcWrite;
497 
[7bbbef]498  n->cfRead    = ngcRead;
499  n->cfPower   = ngcPower;
[51d835]500  n->cfSetMap = ngcSetMap;
[7bbbef]501  n->cfRePart  = ngcRePart;
502  n->cfImPart  = ngcImPart;
[7a8011]503  n->cfCoeffWrite = ngcCoeffWrite;
[7bbbef]504    // cfSize  = ndSize;
[51d835]505#ifdef LDEBUG
[7bbbef]506  n->cfDBTest  = ndDBTest; // not yet implemented: ngcDBTest
[51d835]507#endif
508
[32cc7e]509  n->nCoeffIsEqual = ngcCoeffIsEqual;
[039016]510
[32cc7e]511  n->cfSetChar=ngcSetChar;
[51d835]512
[8df232]513  n->cfInit_bigint=ngcMapQ;
[9bb5457]514
[619d03]515// we need to initialize n->nNULL at least for minpoly printing
516  n->nNULL  = n->cfInit(0,n);
517
[9bb5457]518/*
[51d835]519  //r->cfInitChar=nlInitChar;
520  r->cfKillChar=NULL;
521
[7bbbef]522  r->cfMult  = nlMult;
523  r->cfSub   = nlSub;
524  r->cfAdd   = nlAdd;
525  r->cfDiv   = nlDiv;
526  r->cfIntDiv= nlIntDiv;
527  r->cfIntMod= nlIntMod;
528  r->cfExactDiv= nlExactDiv;
[51d835]529  r->cfInit = nlInit;
[7bbbef]530  r->cfSize  = nlSize;
531  r->cfInt  = nlInt;
[51d835]532#ifdef HAVE_RINGS
[7bbbef]533  r->cfDivComp = NULL; // only for ring stuff
534  r->cfIsUnit = NULL; // only for ring stuff
535  r->cfGetUnit = NULL; // only for ring stuff
536  r->cfExtGcd = NULL; // only for ring stuff
[51d835]537#endif
[7bbbef]538  r->cfNeg   = nlNeg;
539  r->cfInvers= nlInvers;
[51d835]540  r->cfCopy  = nl_Copy;
[7bbbef]541  r->cfRePart = nl_Copy;
542  r->cfImPart = ndReturn0;
[ce1f78]543  r->cfWriteLong = nlWrite;
[7bbbef]544  r->cfRead = nlRead;
545  r->cfNormalize=nlNormalize;
546  r->cfGreater = nlGreater;
[51d835]547#ifdef HAVE_RINGS
[7bbbef]548  r->cfDivBy = NULL; // only for ring stuff
[51d835]549#endif
[7bbbef]550  r->cfEqual = nlEqual;
551  r->cfIsZero = nlIsZero;
552  r->cfIsOne = nlIsOne;
553  r->cfIsMOne = nlIsMOne;
554  r->cfGreaterZero = nlGreaterZero;
555  r->cfPower = nlPower;
[51d835]556  r->cfGetDenom = nlGetDenom;
557  r->cfGetNumerator = nlGetNumerator;
[7bbbef]558  r->cfGcd  = nlGcd;
559  r->cfLcm  = nlLcm;
[51d835]560  r->cfDelete= nlDelete;
561  r->cfSetMap = nlSetMap;
[7bbbef]562  r->cfName = ndName;
563  r->cfInpMult=nlInpMult;
564  r->cfInit_bigint=nlCopyMap;
[51d835]565#ifdef LDEBUG
566  // debug stuff
[7bbbef]567  r->cfDBTest=nlDBTest;
[51d835]568#endif
569
570  // the variables:
571  r->nNULL = INT_TO_SR(0);
572  r->type = n_Q;
573  r->ch = 0;
574  r->has_simple_Alloc=FALSE;
575  r->has_simple_Inverse=FALSE;
576*/
[7fee876]577
578  n->iNumberOfParameters = 1;
579  n->cfParameter = ngcParameter;
580
581  char ** pParameterNames = (char **) omAlloc0(sizeof(char *));
582
[733d24]583  if( parameter != NULL)
584  {
585    LongComplexInfo* p = (LongComplexInfo*)parameter;
[7fee876]586    pParameterNames[0] = omStrDup(p->par_name); //TODO use omAlloc for allocating memory and use strcpy?
[733d24]587    n->float_len = p->float_len;
588    n->float_len2 = p->float_len2;
589   
590  } else // default values, just for testing!
591  {
[7fee876]592    pParameterNames[0] = omStrDup("i");
[733d24]593    n->float_len = SHORT_REAL_LENGTH;
594    n->float_len2 = SHORT_REAL_LENGTH;     
595  }
596   
597  assume( n->float_len <= n->float_len2 );
598  assume( n->float_len2 >= SHORT_REAL_LENGTH );
[7fee876]599  assume( pParameterNames != NULL );
600  assume( pParameterNames[0] != NULL );
601 
602  n->pParameterNames = pParameterNames;
[9bb5457]603
[7fee876]604  // NOTE: n->complex_parameter was replaced by n_ParameterNames(n)[0]
605  // TODO: nfKillChar MUST destroy n->pParameterNames[0] (0-term. string) && n->pParameterNames (array of size 1)
606 
[5d594a9]607  return FALSE;
[51d835]608}
609
[32cc7e]610void ngcSetChar(const coeffs r)
611{
612  setGMPFloatDigits(r->float_len, r->float_len2);
613}
[51d835]614
615
616
617number ngcMapQ(number from, const coeffs aRing, const coeffs r)
618{
619  assume( getCoeffType(r) == ID );
620  assume( getCoeffType(aRing) == n_Q );
621
622  if ( from != NULL )
623  {
624    gmp_complex *res=new gmp_complex(numberFieldToFloat(from,QTOF,aRing));
625    return (number)res;
626  }
627  else
628    return NULL;
629}
630
631static number ngcMapLongR(number from, const coeffs aRing, const coeffs r)
632{
633  assume( getCoeffType(r) == ID );
634  assume( getCoeffType(aRing) == n_long_R );
635
636  if ( from != NULL )
637  {
638    gmp_complex *res=new gmp_complex(*((gmp_float *)from));
639    return (number)res;
640  }
641  else
642    return NULL;
643}
644
645static number ngcMapR(number from, const coeffs aRing, const coeffs r)
646{
647  assume( getCoeffType(r) == ID );
648  assume( getCoeffType(aRing) == n_R );
649
650  if ( from != NULL )
651  {
652    gmp_complex *res=new gmp_complex((double)nrFloat(from));
653    return (number)res;
654  }
655  else
656    return NULL;
657}
658
659static number ngcMapP(number from, const coeffs aRing, const coeffs r)
660{
661  assume( getCoeffType(r) == ID );
662  assume( getCoeffType(aRing) ==  n_Zp );
663
[210852]664  if ( from != NULL )
[51d835]665    return ngcInit(npInt(from, aRing), r);
666  else
667    return NULL;
668}
669
670static number ngcCopyMap(number from, const coeffs aRing, const coeffs r)
671{
672  assume( getCoeffType(r) == ID );
673  assume( getCoeffType(aRing) ==  ID );
674
675  gmp_complex* b = NULL;
676
677  if ( from !=  NULL )
[9bb5457]678  {
[51d835]679    b = new gmp_complex( *(gmp_complex*)from );
680  }
[9bb5457]681  return (number)b;
[51d835]682}
683
684nMapFunc ngcSetMap(const coeffs src, const coeffs dst)
685{
686  assume( getCoeffType(dst) == ID );
687
[1cce47]688  if (nCoeff_is_Q(src))
[51d835]689  {
690    return ngcMapQ;
691  }
[1cce47]692  if (nCoeff_is_long_R(src))
[51d835]693  {
694    return ngcMapLongR;
695  }
[1cce47]696  if (nCoeff_is_long_C(src))
[51d835]697  {
698    return ngcCopyMap;
699  }
[1cce47]700  if (nCoeff_is_R(src))
[51d835]701  {
702    return ngcMapR;
703  }
[1cce47]704  if (nCoeff_is_Zp(src))
[51d835]705  {
706    return ngcMapP;
707  }
708  return NULL;
709}
710
[2e4ec14]711void    ngcCoeffWrite  (const coeffs r, BOOLEAN /*details*/)
[7a8011]712{
713  Print("//   characteristic : 0 (complex:%d digits, additional %d digits)\n",
[03f7b5]714        r->float_len, r->float_len2);  /* long C */
[7fee876]715  Print("//   1 parameter    : %s \n", n_ParameterNames(r)[0]); // this trailing space is for compatibility with the legacy Singular
716  Print("//   minpoly        : (%s^2+1)\n", n_ParameterNames(r)[0]); 
[7a8011]717}
Note: See TracBrowser for help on using the repository browser.