Changeset a507140 in git for libpolys/coeffs/rmodulon.cc


Ignore:
Timestamp:
May 10, 2020, 5:39:11 PM (4 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
f050a38f7d4a93811fa78a1a7cebd7b3a35fc044fe09a23b169ca576a8128e614973bc79bcfec5d7
Parents:
6dd33c01a9c354dd3b89fe045bffa9b635e23954
Message:
opt: nCoeffWrite/nCoeffString via nCoeffName
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/rmodulon.cc

    r6dd33c ra507140  
    3232
    3333EXTERN_VAR omBin gmp_nrz_bin;
    34 
    35 static void nrnCoeffWrite  (const coeffs r, BOOLEAN /*details*/)
    36 {
    37   size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) + 2;
    38   char* s = (char*) omAlloc(l);
    39   s= mpz_get_str (s, 10, r->modBase);
    40 
    41   #ifdef TEST_ZN_AS_ZP
    42   if (l<10)
    43   {
    44     if (nCoeff_is_Zn(r)) Print("ZZ/%s", s);
    45     else if (nCoeff_is_Ring_PtoM(r)) Print("ZZ/(%s^%lu)", s, r->modExponent);
    46   }
    47   else
    48   #endif
    49   {
    50     if (nCoeff_is_Zn(r)) Print("ZZ/bigint(%s)", s);
    51     else if (nCoeff_is_Ring_PtoM(r)) Print("ZZ/(bigint(%s)^%lu)", s, r->modExponent);
    52   }
    53 
    54   omFreeSize((ADDRESS)s, l);
    55 }
    5634
    5735coeffs nrnInitCfByName(char *s,n_coeffType n)
     
    8967  size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) + 2;
    9068  char* s = (char*) omAlloc(l);
    91   l+=22;
     69  l+=24;
    9270  nrnCoeffName_buff=(char*)omAlloc(l);
    9371  s= mpz_get_str (s, 10, r->modBase);
    9472  int ll;
    9573  if (nCoeff_is_Zn(r))
    96     ll=snprintf(nrnCoeffName_buff,l,"ZZ/bigint(%s)",s);
     74  {
     75    if (strlen(s)<10)
     76      ll=snprintf(nrnCoeffName_buff,l,"ZZ/(%s)",s);
     77    else
     78      ll=snprintf(nrnCoeffName_buff,l,"ZZ/bigint(%s)",s);
     79  }
    9780  else if (nCoeff_is_Ring_PtoM(r))
    98     ll=snprintf(nrnCoeffName_buff,l,"ZZ/bigint(%s)^%lu",s,r->modExponent);
     81    ll=snprintf(nrnCoeffName_buff,l,"ZZ/(bigint(%s)^%lu)",s,r->modExponent);
    9982  assume(ll<(int)l); // otherwise nrnCoeffName_buff too small
    10083  omFreeSize((ADDRESS)s, l-22);
     
    10891  return (n==r->type) && (r->modExponent==info->exp)
    10992  && (mpz_cmp(r->modBase,info->base)==0);
    110 }
    111 
    112 static char* nrnCoeffString(const coeffs r)
    113 {
    114   size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) +2;
    115   char* b = (char*) omAlloc(l);
    116   b= mpz_get_str (b, 10, r->modBase);
    117   char* s = (char*) omAlloc(15+l);
    118   if (nCoeff_is_Zn(r)) sprintf(s,"ZZ/%s",b);
    119   else /*if (nCoeff_is_Ring_PtoM(r))*/ sprintf(s,"ZZ/(bigint(%s)^%lu)",b,r->modExponent);
    120   omFreeSize(b,l);
    121   return s;
    12293}
    12394
     
    1014985  r->rep=n_rep_gmp;
    1015986
    1016 
    1017   r->cfCoeffString = nrnCoeffString;
    1018 
    1019987  r->cfInit        = nrnInit;
    1020988  r->cfDelete      = nrnDelete;
     
    10521020  r->cfQuotRem     = nrnQuotRem;
    10531021  r->cfCoeffName   = nrnCoeffName;
    1054   r->cfCoeffWrite  = nrnCoeffWrite;
    10551022  r->nCoeffIsEqual = nrnCoeffIsEqual;
    10561023  r->cfKillChar    = nrnKillChar;
Note: See TracChangeset for help on using the changeset viewer.