Changeset 3216ec in git


Ignore:
Timestamp:
Aug 15, 2012, 1:44:30 PM (10 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '96ce329119711a2b80858c8365abd29f8460bbfa')
Children:
d8b0997ff6f148513d95e2f2a5a075c7386c7168
Parents:
a8ead8e63f3539f8915726efa18791dcc052733a
Message:
add: extgcd for bigint
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Singular/iparith.cc

    ra8ead8 r3216ec  
    19741974  inerror=3;
    19751975  return TRUE;
     1976}
     1977static BOOLEAN jjEXTGCD_BI(leftv res, leftv u, leftv v)
     1978{
     1979  number uu=(number)u->Data();number vv=(number)v->Data();
     1980  lists L=(lists)omAllocBin(slists_bin);
     1981  number a,b;
     1982  number p0=n_ExtGcd(uu,vv,&a,&b,coeffs_BIGINT);
     1983  L->Init(3);
     1984  L->m[0].rtyp=BIGINT_CMD;   L->m[0].data=(void *)p0;
     1985  L->m[1].rtyp=BIGINT_CMD;   L->m[1].data=(void *)a;
     1986  L->m[2].rtyp=BIGINT_CMD;   L->m[2].data=(void *)b;
     1987  res->rtyp=LIST_CMD;
     1988  res->data=(char *)L;
     1989  return FALSE;
    19761990}
    19771991static BOOLEAN jjEXTGCD_I(leftv res, leftv u, leftv v)
  • Singular/table.h

    ra8ead8 r3216ec  
    526526,{D(jjEXPORTTO),  EXPORTTO_CMD,   NONE,           PACKAGE_CMD, IDHDL, ALLOW_PLURAL |ALLOW_RING}
    527527,{D(jjEXTGCD_I),  EXTGCD_CMD,     LIST_CMD,       INT_CMD,    INT_CMD, ALLOW_PLURAL |ALLOW_RING}
     528,{D(jjEXTGCD_BI), EXTGCD_CMD,     LIST_CMD,       BIGINT_CMD, BIGINT_CMD, ALLOW_PLURAL |ALLOW_RING}
    528529#ifdef HAVE_FACTORY
    529530,{D(jjEXTGCD_P),  EXTGCD_CMD,     LIST_CMD,       POLY_CMD,   POLY_CMD, NO_PLURAL |NO_RING}
  • libpolys/coeffs/coeffs.h

    ra8ead8 r3216ec  
    143143   BOOLEAN (*cfIsUnit)(number a,const coeffs r);
    144144   number  (*cfGetUnit)(number a,const coeffs r);
    145    number  (*cfExtGcd)(number a, number b, number *s, number *t,const coeffs r);
    146145#endif
    147146
     
    181180   number  (*cfGetNumerator)(number &n, const coeffs r);
    182181   number  (*cfGcd)(number a, number b, const coeffs r);
     182   number  (*cfExtGcd)(number a, number b, number *s, number *t,const coeffs r);
    183183   number  (*cfLcm)(number a, number b, const coeffs r);
    184184   void    (*cfDelete)(number * a, const coeffs r);
  • libpolys/coeffs/longrat.cc

    ra8ead8 r3216ec  
    26052605}
    26062606
     2607number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
     2608{
     2609  mpz_t aa,bb;
     2610  *s=ALLOC_RNUMBER();
     2611  mpz_init((*s)->z); (*s)->s=3;
     2612  (*t)=ALLOC_RNUMBER();
     2613  mpz_init((*t)->z); (*t)->s=3;
     2614  number g=ALLOC_RNUMBER();
     2615  mpz_init(g->z); g->s=3;
     2616  if (SR_HDL(a) & SR_INT)
     2617  {
     2618    mpz_init_set_si(aa,SR_TO_INT(a));
     2619  }
     2620  else
     2621  {
     2622    mpz_init_set(aa,a->z);
     2623  }
     2624  if (SR_HDL(b) & SR_INT)
     2625  {
     2626    mpz_init_set_si(bb,SR_TO_INT(b));
     2627  }
     2628  else
     2629  {
     2630    mpz_init_set(bb,b->z);
     2631  }
     2632  mpz_gcdext(g->z,(*s)->z,(*t)->z,aa,bb);
     2633  mpz_clear(aa);
     2634  mpz_clear(bb);
     2635  (*s)=nlShort3((*s));
     2636  (*t)=nlShort3((*t));
     2637  g=nlShort3(g);
     2638  return g;
     2639}
     2640
    26072641void    nlCoeffWrite  (const coeffs, BOOLEAN /*details*/)
    26082642{
     
    28162850  //r->cfIsUnit = NULL; // only for ring stuff
    28172851  //r->cfGetUnit = NULL; // only for ring stuff
    2818   //r->cfExtGcd = NULL; // only for ring stuff
    28192852  //r->cfDivBy = NULL; // only for ring stuff
    28202853  #endif
     
    28372870  r->cfGetNumerator = nlGetNumerator;
    28382871  r->cfGcd  = nlGcd;
     2872  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
    28392873  r->cfLcm  = nlLcm;
    28402874  r->cfDelete= nlDelete;
  • libpolys/coeffs/longrat.h

    ra8ead8 r3216ec  
    6565
    6666number   nlGcd(number a, number b, const coeffs r);
     67number nlExtGcd(number a, number b, number *s, number *t, const coeffs);
    6768number   nlLcm(number a, number b, const coeffs r);   /*special routine !*/
    6869BOOLEAN  nlGreater(number a, number b, const coeffs r);
Note: See TracChangeset for help on using the changeset viewer.