source: git/libpolys/coeffs/numbers.cc @ 06b685

spielwiese
Last change on this file since 06b685 was 06b685, checked in by Hans Schoenemann <hannes@…>, 20 months ago
typo
  • Property mode set to 100644
File size: 18.1 KB
Line 
1/*****************************************
2*  Computer Algebra System SINGULAR      *
3*****************************************/
4
5/*
6* ABSTRACT: interface to coefficient aritmetics
7*/
8
9#include <string.h>
10#include <stdlib.h>
11
12#include "misc/auxiliary.h"
13#include "misc/mylimits.h"
14#include "factory/factory.h"
15
16#include "reporter/reporter.h"
17
18#include "coeffs/coeffs.h"
19#include "coeffs/numbers.h"
20
21#include "coeffs/longrat.h"
22#include "coeffs/modulop.h"
23#include "coeffs/gnumpfl.h"
24#include "coeffs/gnumpc.h"
25#include "coeffs/ffields.h"
26#include "coeffs/shortfl.h"
27#include "coeffs/ntupel.h"
28#include "coeffs/flintcf_Qrat.h"
29
30#ifdef HAVE_RINGS
31#include "coeffs/rmodulo2m.h"
32#include "coeffs/rmodulon.h"
33#include "coeffs/rintegers.h"
34#endif
35
36#ifdef HAVE_POLYEXTENSIONS
37#include "polys/ext_fields/algext.h"
38#include "polys/ext_fields/transext.h"
39#endif
40
41
42//static int characteristic = 0;
43//extern int IsPrime(int p);
44
45VAR n_Procs_s *cf_root=NULL;
46
47void   nNew(number* d) { *d=NULL; }
48
49
50static void   ndDelete(number* d, const coeffs) { *d=NULL; }
51static number ndAnn(number, const coeffs) { return NULL;}
52static char* ndCoeffString(const coeffs r)
53{
54  return omStrDup(r->cfCoeffName(r));
55}
56static void ndCoeffWrite(const coeffs r,BOOLEAN)
57{
58  PrintS(r->cfCoeffName(r));
59}
60static char* ndCoeffName(const coeffs r)
61{
62  STATIC_VAR char s[20];
63  snprintf(s,11,"Coeffs(%d)",r->type);
64  return s;
65}
66static void   ndInpMult(number &a, number b, const coeffs r)
67{
68  number n=r->cfMult(a,b,r);
69  r->cfDelete(&a,r);
70  a=n;
71}
72void ndInpAdd(number &a, number b, const coeffs r)
73{
74  number n=r->cfAdd(a,b,r);
75  r->cfDelete(&a,r);
76  a=n;
77}
78
79static void ndPower(number a, int i, number * res, const coeffs r)
80{
81  if (i==0)
82  {
83    *res = r->cfInit(1, r);
84  }
85  else if (i==1)
86  {
87    *res = r->cfCopy(a, r);
88  }
89  else if (i==2)
90  {
91    *res = r->cfMult(a, a, r);
92  }
93  else if (i<0)
94  {
95    number b = r->cfInvers(a, r);
96    ndPower(b, -i, res, r);
97    r->cfDelete(&b, r);
98  }
99  else
100  {
101    ndPower(a, i/2, res, r);
102    r->cfInpMult(*res, *res, r);
103    if (i&1)
104    {
105      r->cfInpMult(*res, a, r);
106    }
107  }
108}
109static number ndInvers(number a, const coeffs r)
110{
111  number one=r->cfInit(1,r);
112  number res=r->cfDiv(one,a,r);
113  r->cfDelete(&one,r);
114  return res;
115}
116static number ndInvers_Ring(number a, const coeffs r)
117{
118  if (!r->cfIsUnit(a,r)) Print("ndInvers_Ring used with non-unit\n");
119  number one=r->cfInit(1,r);
120  number res=r->cfDiv(one,a,r);
121  r->cfDelete(&one,r);
122  return res;
123}
124
125static BOOLEAN ndIsUnit_Ring(number a, const coeffs r)
126{ return r->cfIsOne(a,r)|| r->cfIsMOne(a,r); }
127static BOOLEAN ndIsUnit_Field(number a, const coeffs r)
128{ return !r->cfIsZero(a,r); }
129static number ndGetUnit_Ring(number, const coeffs r)
130{ return r->cfInit(1,r); }
131static number ndRandom(siRandProc p, number p1, number p2, const coeffs cf)
132{ return cf->cfInit(p(),cf); }
133static number ndEucNorm(number a, const coeffs cf)
134{ return cf->cfInit(cf->cfSize(a,cf),cf); }
135#ifdef LDEBUG
136// static void   nDBDummy1(number* d,char *, int) { *d=NULL; }
137static BOOLEAN ndDBTest(number, const char *, const int, const coeffs){ return TRUE; }
138#endif
139
140static number ndFarey(number,number,const coeffs r)
141{
142  Werror("farey not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
143  return NULL;
144}
145static number ndXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
146{
147  Werror("XExtGcd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
148  return NULL;
149}
150static number ndChineseRemainder(number *,number *,int,BOOLEAN,CFArray&,const coeffs r)
151{
152  Werror("ChineseRemainder not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
153  return r->cfInit(0,r);
154}
155number ndReadFd( const ssiInfo *f, const coeffs r)
156{
157  Warn("ReadFd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
158  return NULL;
159}
160
161static void ndWriteFd(number a, const ssiInfo *f, const coeffs r)
162{
163  Warn("WriteFd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
164}
165
166static int ndParDeg(number n, const coeffs r)
167{
168  return (-r->cfIsZero(n,r));
169}
170
171static number ndParameter(const int, const coeffs r)
172{
173  return r->cfInit(1,r);
174}
175
176BOOLEAN n_IsZeroDivisor( number a, const coeffs r)
177{
178  BOOLEAN ret = n_IsZero(a, r);
179  int c = n_GetChar(r);
180  if (ret || (c==0) || (r->is_field))
181    return ret; /*n_IsZero(a, r)*/
182  number ch = n_Init( c, r );
183  number g = n_Gcd( ch, a, r );
184  ret = !n_IsOne (g, r);
185  n_Delete(&ch, r);
186  n_Delete(&g, r);
187  return ret;
188}
189
190void   ndNormalize(number&, const coeffs) { }
191static number ndReturn0(number, const coeffs r)        { return r->cfInit(0,r); }
192number ndGcd(number, number, const coeffs r)    { return r->cfInit(1,r); }
193static number ndIntMod(number a, number b, const coeffs R)
194{
195  if (R->is_field)
196    return R->cfInit(0,R);
197  else // implementation for a non-field:
198  {
199    number d=n_Div(a,b,R);
200    number p=n_Mult(b,d,R);
201    number r=n_Sub(a,p,R);
202    n_Delete(&p,R);
203    n_Delete(&d,R);
204    return r;
205  }
206}
207static number ndGetDenom(number &, const coeffs r)     { return r->cfInit(1,r); }
208static number ndGetNumerator(number &a,const coeffs r) { return r->cfCopy(a,r); }
209static int    ndSize(number a, const coeffs r)         { return (int)r->cfIsZero(a,r)==FALSE; }
210
211static void ndClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs r)
212{
213  assume(r != NULL);
214
215  // no fractions
216  assume(!(  nCoeff_is_Q(r) ));
217  // all coeffs are given by integers!!!
218
219  numberCollectionEnumerator.Reset();
220
221  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
222  {
223    c = n_Init(1, r);
224    return;
225  }
226
227  number &curr = numberCollectionEnumerator.Current();
228
229#ifdef HAVE_RINGS
230  /// TODO: move to a separate implementation
231  if (nCoeff_is_Ring(r))
232  {
233    if (nCoeff_has_Units(r))
234    {
235      c = n_GetUnit(curr, r);
236
237      if (!n_IsOne(c, r))
238      {
239        number inv = n_Invers(c, r);
240
241        n_InpMult(curr, inv, r);
242
243        while( numberCollectionEnumerator.MoveNext() )
244        {
245          number &n = numberCollectionEnumerator.Current();
246          n_Normalize(n, r); // ?
247          n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
248        }
249
250        n_Delete(&inv, r);
251      }
252    } else c = n_Init(1, r);
253
254    return;
255  }
256#endif
257
258  assume(!nCoeff_is_Ring(r));
259  assume(nCoeff_is_Zp(r) || nCoeff_is_numeric(r) || nCoeff_is_GF(r) || nCoeff_is_Zp_a(r) || nCoeff_is_Q_algext(r));
260
261  n_Normalize(curr, r); // Q: good/bad/ugly??
262
263  if (!n_IsOne(curr, r))
264  {
265    number t = curr; // takes over the curr! note: not a reference!!!
266
267    curr = n_Init(1, r); // ???
268
269    number inv = n_Invers(t, r);
270
271    while( numberCollectionEnumerator.MoveNext() )
272    {
273      number &n = numberCollectionEnumerator.Current();
274      n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
275//      n_Normalize(n, r); // ?
276    }
277
278    n_Delete(&inv, r);
279
280    c = t;
281  } else
282    c = n_Copy(curr, r); // c == 1 and nothing else to do...
283}
284
285static void ndClearDenominators(ICoeffsEnumerator& /*numberCollectionEnumerator*/, number& d, const coeffs r)
286{
287  assume( r != NULL );
288  assume( !(nCoeff_is_Q(r) || nCoeff_is_transExt(r) || nCoeff_is_algExt(r)) );
289  assume( nCoeff_is_Ring(r) || nCoeff_is_Zp(r) || nCoeff_is_numeric(r) || nCoeff_is_GF(r) );
290
291  d = n_Init(1, r);
292}
293
294static number ndCopy(number a, const coeffs) { return a; }
295number ndCopyMap(number a, const coeffs aRing, const coeffs r)
296{
297  // aRing and r need not be the same, but must be the same representation
298  assume(aRing->rep==r->rep);
299  if ( nCoeff_has_simple_Alloc(r) && nCoeff_has_simple_Alloc(aRing) )
300    return a;
301  else
302    return r->cfCopy(a, r);
303}
304
305static void ndKillChar(coeffs) {}
306static void ndSetChar(const coeffs) {}
307
308number nd_Copy(number a, const coeffs r) { return r->cfCopy(a, r); }
309
310#ifdef HAVE_RINGS
311static BOOLEAN ndDivBy(number, number, const coeffs) { return TRUE; } // assume a,b !=0
312static int ndDivComp(number, number, const coeffs) { return 2; }
313static number  ndExtGcd (number, number, number *, number *, const coeffs r) { return r->cfInit(1,r); }
314#endif
315
316CanonicalForm ndConvSingNFactoryN( number, BOOLEAN /*setChar*/, const coeffs)
317{
318  CanonicalForm term(0);
319  WerrorS("no conversion to factory");
320  return term;
321}
322
323static number ndConvFactoryNSingN( const CanonicalForm, const coeffs)
324{
325  WerrorS("no conversion from factory");
326  return NULL;
327}
328
329/**< [in, out] a bigint number >= 0  */
330/**< [out] the GMP equivalent    */
331/// Converts a non-negative bigint number into a GMP number.
332static void ndMPZ(mpz_t result, number &n, const coeffs r)
333{
334  mpz_init_set_si( result, r->cfInt(n, r) );
335}
336
337static number ndInitMPZ(mpz_t m, const coeffs r)
338{
339  return r->cfInit( mpz_get_si(m), r);
340}
341
342static const char *ndRead(const char * s, number *, const coeffs r)
343{
344  Werror("cfRead is undefined for %s",nCoeffString(r));
345  return s;
346}
347static nMapFunc ndSetMap(const coeffs src, const coeffs dst)
348{
349  if (src==dst) return ndCopyMap;
350  Werror("cfSetMap is undefined for %s",nCoeffString(dst));
351  return NULL;
352}
353
354static BOOLEAN ndCoeffIsEqual(const coeffs r, n_coeffType n, void *)
355{
356  /* test, if r is an instance of nInitCoeffs(n,parameter) */
357  /* if parameter is not needed */
358  return (n==r->type);
359}
360
361number ndQuotRem (number a, number b, number * r, const coeffs R)
362{
363  // implementation for a field: r: 0, result: n_Div
364  if(R->is_field)
365  {
366    *r=n_Init(0,R);
367    return n_Div(a,b,R);
368  }
369  else
370  // implementation for a non-field:
371  {
372    number d=n_Div(a,b,R);
373    number p=n_Mult(b,d,R);
374    *r=n_Sub(a,p,R);
375    n_Delete(&p,R);
376    return d;
377  }
378}
379STATIC_VAR n_coeffType nLastCoeffs=n_CF;
380VAR cfInitCharProc nInitCharTableDefault[]=
381{ NULL,        /*n_unknown */
382 npInitChar,   /* n_Zp */
383 nlInitChar,   /* n_Q */
384 nrInitChar,   /* n_R */
385 nfInitChar,   /* n_GF */
386 ngfInitChar,  /* n_long_R */
387 #ifdef HAVE_POLYEXTENSIONS
388 n2pInitChar, /* n_polyExt */
389 naInitChar,  /* n_algExt */
390 ntInitChar,  /* n_transExt */
391 #else
392 NULL,        /* n_polyExt */
393 NULL,        /* n_algExt */
394 NULL,        /* n_transExt */
395 #endif
396 ngcInitChar,  /* n_long_C */
397 nnInitChar,   /* n_nTupel */
398 #ifdef HAVE_RINGS
399 nrzInitChar,  /* n_Z */
400 nrnInitChar,  /* n_Zn */
401 nrnInitChar,  /* n_Znm */
402 nr2mInitChar, /* n_Z2m */
403 #else
404 NULL,         /* n_Z */
405 NULL,         /* n_Zn */
406 NULL,         /* n_Znm */
407 NULL,         /* n_Z2m */
408 #endif
409 flintQrat_InitChar, /* n_FlintQrat */
410 NULL         /* n_CF */
411};
412
413STATIC_VAR cfInitCharProc *nInitCharTable=nInitCharTableDefault;
414/*2
415* init operations for coeffs r
416*/
417coeffs nInitChar(n_coeffType t, void * parameter)
418{
419  n_Procs_s *n=cf_root;
420
421  while((n!=NULL) && (n->nCoeffIsEqual!=NULL) && (!n->nCoeffIsEqual(n,t,parameter)))
422      n=n->next;
423
424  if (n==NULL)
425  {
426    n=(n_Procs_s*)omAlloc0(sizeof(n_Procs_s));
427    n->next=cf_root;
428    n->ref=1;
429    n->type=t;
430
431    // default entries (different from NULL) for some routines:
432    n->nCoeffIsEqual = ndCoeffIsEqual;
433    n->cfSize = ndSize;
434    n->cfGetDenom= ndGetDenom;
435    n->cfGetNumerator= ndGetNumerator;
436    n->cfImPart=ndReturn0;
437    n->cfDelete= ndDelete;
438    n->cfAnn = ndAnn;
439    n->cfCoeffString = ndCoeffString;
440    n->cfCoeffWrite = ndCoeffWrite;
441    n->cfCoeffName = ndCoeffName; // should alway be changed!
442    n->cfInpAdd=ndInpAdd;
443    n->cfInpMult=ndInpMult;
444    n->cfCopy = ndCopy;
445    n->cfIntMod=ndIntMod; /* dummy !! */
446    n->cfNormalize=ndNormalize;
447    n->cfGcd  = ndGcd;
448    n->cfNormalizeHelper  = ndGcd; /* tricky, isn't it ?*/
449    n->cfLcm  = ndGcd; /* tricky, isn't it ?*/
450    n->cfInitMPZ = ndInitMPZ;
451    n->cfMPZ = ndMPZ;
452    n->cfPower = ndPower;
453    n->cfQuotRem = ndQuotRem;
454    n->cfInvers = ndInvers;
455    n->cfRandom = ndRandom;
456
457    n->cfKillChar = ndKillChar; /* dummy */
458    n->cfSetChar = ndSetChar; /* dummy */
459    // temp. removed to catch all the coeffs which miss to implement this!
460
461    n->cfChineseRemainder = ndChineseRemainder; /* not implemented */
462    n->cfFarey = ndFarey; /* not implemented */
463    n->cfParDeg = ndParDeg; /* not implemented */
464    n->cfReadFd = ndReadFd; /* not implemented */
465    n->cfWriteFd = ndWriteFd; /* not implemented */
466
467    n->cfParameter = ndParameter;
468
469    n->cfClearContent = ndClearContent;
470    n->cfClearDenominators = ndClearDenominators;
471
472    n->cfEucNorm = ndEucNorm;
473#ifdef HAVE_RINGS
474    n->cfDivComp = ndDivComp;
475    n->cfDivBy = ndDivBy;
476    n->cfExtGcd = ndExtGcd;
477    n->cfXExtGcd = ndXExtGcd;
478    //n->cfGetUnit = ndGetUnit_Ring;// set afterwards
479#endif
480
481    // report error, if not redefined
482    n->cfRead=ndRead;
483    n->cfSetMap=ndSetMap;
484
485#ifdef LDEBUG
486    n->cfDBTest=ndDBTest;
487#endif
488
489    n->convSingNFactoryN=ndConvSingNFactoryN;
490    n->convFactoryNSingN=ndConvFactoryNSingN;
491
492    BOOLEAN nOK=TRUE;
493    // init
494    if ((t<=nLastCoeffs) && (nInitCharTable[t]!=NULL))
495      nOK = (nInitCharTable[t])(n,parameter);
496    else
497       Werror("Sorry: the coeff type [%d] was not registered: it is missing in nInitCharTable", (int)t);
498    if (nOK)
499    {
500      omFreeSize(n,sizeof(*n));
501      return NULL;
502    }
503    cf_root=n;
504    // post init settings:
505    if (n->cfRePart==NULL) n->cfRePart=n->cfCopy;
506    if (n->cfExactDiv==NULL) n->cfExactDiv=n->cfDiv;
507    if (n->cfSubringGcd==NULL) n->cfSubringGcd=n->cfGcd;
508    if (n->cfWriteShort==NULL) n->cfWriteShort = n->cfWriteLong;
509    if (n->cfIsUnit==NULL)
510    {
511      if (n->is_field) n->cfIsUnit=ndIsUnit_Field;
512      else             n->cfIsUnit=ndIsUnit_Ring;
513    }
514    #ifdef HAVE_RINGS
515    if (n->cfGetUnit==NULL)
516    {
517      if (n->is_field) n->cfGetUnit=n->cfCopy;
518      else             n->cfGetUnit=ndGetUnit_Ring;
519    }
520    if ((n->cfInvers==ndInvers)&&(n->is_field))
521    {
522      n->cfInvers=ndInvers_Ring;
523    }
524    #endif
525
526
527    if(n->cfMult==NULL)  PrintS("cfMult missing\n");
528    if(n->cfSub==NULL)  PrintS("cfSub missing\n");
529    if(n->cfAdd==NULL) PrintS("cfAdd missing\n");
530    if(n->cfDiv==NULL) PrintS("cfDiv missing\n");
531    if(n->cfExactDiv==NULL) PrintS("cfExactDiv missing\n");
532    if(n->cfInit==NULL) PrintS("cfInit missing\n");
533    if(n->cfInt==NULL) PrintS("cfInt missing\n");
534    if(n->cfIsUnit==NULL) PrintS("cfIsUnit missing\n");
535    if(n->cfGetUnit==NULL) PrintS("cfGetUnit missing\n");
536    if(n->cfInpNeg==NULL)  PrintS("cfInpNeg missing\n");
537    if(n->cfXExtGcd==NULL)  PrintS("cfXExtGcd missing\n");
538    if(n->cfAnn==NULL)  PrintS("cfAnn missing\n");
539    if(n->cfWriteLong==NULL) PrintS("cfWriteLong missing\n");
540
541    assume(n->iNumberOfParameters>= 0);
542
543    assume( (n->iNumberOfParameters == 0 && n->pParameterNames == NULL) ||
544            (n->iNumberOfParameters >  0 && n->pParameterNames != NULL) );
545
546
547    if(n->cfGreater==NULL) PrintS("cfGreater missing\n");
548    if(n->cfEqual==NULL) PrintS("cfEqual missing\n");
549    if(n->cfIsZero==NULL) PrintS("cfIsZero missing\n");
550    if(n->cfIsOne==NULL) PrintS("cfIsOne missing\n");
551    if(n->cfIsMOne==NULL) PrintS("cfIsMOne missing\n");
552    if(n->cfGreaterZero==NULL) PrintS("cfGreaterZero missing\n");
553    /* error reporter:
554    if(n->cfRead==ndRead) PrintS("cfRead missing\n");
555    if(n->cfSetMap==ndSetMap) PrintS("cfSetMap missing\n");
556    */
557
558    assume(n->type==t);
559
560#ifndef SING_NDEBUG
561    if(n->cfWriteLong==NULL) Warn("cfWrite is NULL for coeff %d",t);
562    if(n->cfWriteShort==NULL) Warn("cfWriteShort is NULL for coeff %d",t);
563#endif
564  }
565  else
566  {
567    n->ref++;
568  }
569  return n;
570}
571
572void nKillChar(coeffs r)
573{
574  if (r!=NULL)
575  {
576    r->ref--;
577    if (r->ref<=0)
578    {
579      n_Procs_s tmp;
580      n_Procs_s* n=&tmp;
581      tmp.next=cf_root;
582      while((n->next!=NULL) && (n->next!=r)) n=n->next;
583      if (n->next==r)
584      {
585        n->next=n->next->next;
586        if (cf_root==r) cf_root=n->next;
587        assume (r->cfKillChar!=NULL); r->cfKillChar(r);
588        omFreeSize((void *)r, sizeof(n_Procs_s));
589        r=NULL;
590      }
591      else
592      {
593        WarnS("cf_root list destroyed");
594      }
595    }
596  }
597}
598
599n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
600{
601  if (n==n_unknown)
602  {
603    nLastCoeffs=(n_coeffType)(int(nLastCoeffs)+1);
604    if (nInitCharTable==nInitCharTableDefault)
605    {
606      nInitCharTable=(cfInitCharProc*)omAlloc0(
607                                          ((int)nLastCoeffs+1)*sizeof(cfInitCharProc));
608      memcpy(nInitCharTable,nInitCharTableDefault,
609              ((int)nLastCoeffs)*sizeof(cfInitCharProc));
610    }
611    else
612    {
613      nInitCharTable=(cfInitCharProc*)omReallocSize(nInitCharTable,
614                                          ((int)nLastCoeffs)*sizeof(cfInitCharProc),
615                                          (((int)nLastCoeffs)+1)*sizeof(cfInitCharProc));
616    }
617
618    nInitCharTable[nLastCoeffs]=p;
619    return nLastCoeffs;
620  }
621  else
622  {
623    if (nInitCharTable[n]!=NULL) Print("coeff %d already initialized\n",n);
624    nInitCharTable[n]=p;
625    return n;
626  }
627}
628
629struct nFindCoeffByName_s;
630typedef struct nFindCoeffByName_s* nFindCoeffByName_p;
631
632struct nFindCoeffByName_s
633{
634  n_coeffType n;
635  cfInitCfByNameProc p;
636  nFindCoeffByName_p next;
637};
638
639VAR nFindCoeffByName_p nFindCoeffByName_Root=NULL;
640void nRegisterCfByName(cfInitCfByNameProc p,n_coeffType n)
641{
642  nFindCoeffByName_p h=(nFindCoeffByName_p)omAlloc0(sizeof(*h));
643  h->p=p;
644  h->n=n;
645  h->next=nFindCoeffByName_Root;
646  nFindCoeffByName_Root=h;
647}
648
649coeffs nFindCoeffByName(char *cf_name)
650{
651  n_Procs_s* n=cf_root;
652  // try existings coeffs:
653  while(n!=NULL)
654  {
655    if ((n->cfCoeffName!=NULL)
656    && (strcmp(cf_name,n->cfCoeffName(n))==0)) return n;
657    n=n->next;
658  }
659  // TODO: parametrized cf, e.g. flint:Z/26[a]
660  // try existing types:
661  nFindCoeffByName_p p=nFindCoeffByName_Root;
662  while(p!=NULL)
663  {
664    coeffs cf=p->p(cf_name,p->n);
665    if (cf!=NULL) return cf;
666    p=p->next;
667  }
668  return NULL;
669}
670
671void n_Print(number& a,  const coeffs r)
672{
673   assume(r != NULL);
674   n_Test(a,r);
675
676   StringSetS("");
677   n_Write(a, r);
678   { char* s = StringEndS(); Print("%s", s); omFree(s); }
679}
680
681char* nEati(char *s, int *i, int m)
682{
683
684  if (((*s) >= '0') && ((*s) <= '9'))
685  {
686    unsigned long ii=0L;
687    do
688    {
689      ii *= 10;
690      ii += *s++ - '0';
691      if ((m!=0) && (ii > (MAX_INT_VAL / 10))) ii = ii % m;
692    }
693    while (((*s) >= '0') && ((*s) <= '9'));
694    if ((m!=0) && (ii>=(unsigned)m)) ii=ii%m;
695    *i=(int)ii;
696  }
697  else (*i) = 1;
698  return s;
699}
700
701/// extracts a long integer from s, returns the rest
702char * nEatLong(char *s, mpz_ptr i)
703{
704  const char * start=s;
705
706  while (*s >= '0' && *s <= '9') s++;
707  if (*s=='\0')
708  {
709    mpz_set_str(i,start,10);
710  }
711  else
712  {
713    char c=*s;
714    *s='\0';
715    mpz_set_str(i,start,10);
716    *s=c;
717  }
718  return s;
719}
720
Note: See TracBrowser for help on using the repository browser.