Changeset 1fc83c0 in git for Singular/longrat.cc


Ignore:
Timestamp:
Aug 12, 1997, 7:14:45 PM (27 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'fc741b6502fd8a97288eaa3eba6e5220f3c3df87')
Children:
457e2d7f256604a4b31c642f360b63b13a5151cb
Parents:
573ae7acc2dadf68863ca5ee07211c1e9a07b3fb
Message:
* hannes:
  added nExactDiv to numbers
   (numbers.*, longrat.*)
 corrected open bug in sing_dbm.cc (could only "r")
 simplified sing_dbm.cc (many tests already in silink.cc)
   (sing_dbm.cc, silink.h)
 added "mod" (as an alias to "%")
   (iparith.cc)
 updated singular.doc: div/mod, DBM: links
 ANSI-conversion in ndbm.cc (added return types, include files)


git-svn-id: file:///usr/local/Singular/svn/trunk@614 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/longrat.cc

    r573ae7 r1fc83c0  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: longrat.cc,v 1.10 1997-08-08 12:59:22 obachman Exp $ */
     4/* $Id: longrat.cc,v 1.11 1997-08-12 17:14:39 Singular Exp $ */
    55/*
    66* ABSTRACT: computation with long rational numbers (Hubert Grassmann)
     
    12271227
    12281228/*2
     1229* u := a / b in Z, if b | a (else undefined)
     1230*/
     1231number   nlExactDiv(number a, number b)
     1232{
     1233  if (b==INT_TO_SR(0))
     1234  {
     1235    WerrorS("div. by 0");
     1236    return INT_TO_SR(0);
     1237  }
     1238  number u;
     1239  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
     1240  {
     1241    /* the small int -(1<<28) divided by -1 is the large int (1<<28)   */
     1242    if ((a==INT_TO_SR(-(1<<28)))&&(b==INT_TO_SR(-1)))
     1243    {
     1244      return nlRInit(1<<28);
     1245    }
     1246    int aa=SR_TO_INT(a);
     1247    int bb=SR_TO_INT(b);
     1248    return INT_TO_SR(aa/bb);
     1249  }
     1250  number bb=NULL;
     1251  if (SR_HDL(b) & SR_INT)
     1252  {
     1253    bb=nlRInit(SR_TO_INT(b));
     1254    b=bb;
     1255  }
     1256  u=(number)Alloc(sizeof(rnumber));
     1257#ifdef LDEBUG
     1258  u->debug=123456;
     1259#endif
     1260  mpz_init(&u->z);
     1261  /* u=a/b */
     1262  u->s = 3;
     1263  MPZ_EXACTDIV(&u->z,&a->z,&b->z);
     1264  if (bb!=NULL)
     1265  {
     1266    mpz_clear(&bb->z);
     1267    Free((ADDRESS)bb,sizeof(rnumber));
     1268  }
     1269  if (mpz_size1(&u->z)<=MP_SMALL)
     1270  {
     1271    int ui=(int)mpz_get_si(&u->z);
     1272    if ((((ui<<3)>>3)==ui)
     1273    && (mpz_cmp_si(&u->z,(long)ui)==0))
     1274    {
     1275      mpz_clear(&u->z);
     1276      Free((ADDRESS)u,sizeof(rnumber));
     1277      u=INT_TO_SR(ui);
     1278    }
     1279  }
     1280#ifdef LDEBUG
     1281  nlTest(u);
     1282#endif
     1283  return u;
     1284}
     1285
     1286/*2
    12291287* u := a / b in Z
    12301288*/
Note: See TracChangeset for help on using the changeset viewer.