Changeset 121ad4 in git


Ignore:
Timestamp:
May 28, 2014, 5:59:44 PM (10 years ago)
Author:
Adi Popescu <adi_popescum@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
75424e3a56f41323abd6d3f9936e00e102ff6a6d
Parents:
bf8a3f589c629892975963ad0be2ec5ad3f6bf50
git-author:
Adi Popescu <adi_popescum@yahoo.de>2014-05-28 17:59:44+02:00
git-committer:
Adi Popescu <adi_popescum@yahoo.de>2014-05-28 18:03:11+02:00
Message:
fix: 64bit nlIntMod, positive result
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/longrat.cc

    rbf8a3f r121ad4  
    802802    LONG bb=SR_TO_INT(b);
    803803    LONG c=SR_TO_INT(a) % bb;
    804     if(c < 0)
     804    /*if(c < 0)
    805805    {   
    806806        if(bb < 0)
     
    808808        else
    809809            c = c + bb;
    810     }
    811     //printf("\nnlIntMod SR_TO_INT\n");
    812     //n_Print(a,r);
    813     //printf("\na =  %ld\n",SR_TO_INT(a));
    814     //n_Print(b, r);
    815     //printf("\nb =  %ld\n",bb);
    816     //printf("\nc =  %ld\n",c);
     810    }*/
     811    /*if((((SR_TO_INT(a)) / (bb))*bb+c) != SR_TO_INT(a))
     812    {
     813        printf("\nERROR longrat:819\n");
     814        printf("\na = %ld\n",SR_TO_INT(a));
     815        printf("\nb = %ld\n",bb);
     816        printf("\nc = %ld\n",c);
     817    }*/
    817818    return INT_TO_SR(c);
    818819  }
     
    820821  {
    821822    // a is a small and b is a large int: -> a
    822     //  INCORRECT, IT COULD HAPPEN THAT B IS A SMALL NUMBER
     823    //  INCORRECT, IT COULD HAPPEN THAT b IS A SMALL NUMBER
    823824    number aa;
    824     //mpz_ptr aa=NULL;
    825     //aa=(mpz_ptr)omAlloc(sizeof(mpz_t));
    826825    aa=ALLOC_RNUMBER();
    827826    mpz_init(aa->z);
    828827    mpz_set_si(aa->z, SR_TO_INT(a));
    829     //mpz_init_set_si(aa,SR_TO_INT(a));
    830828    u=ALLOC_RNUMBER();
    831829#if defined(LDEBUG)
     
    842840          mpz_add(u->z,aa->z,b->z);
    843841    }
    844     /*if( !n_GreaterZero(a,r) )
    845     {
    846         if( !n_GreaterZero(b,r) )
    847             a = r->cfSub(a,b,r);
    848         else
    849             a = r->cfAdd(a,b,r);
    850     }*/
    851     //printf("\nnlIntMod a\n");
    852     //printf("\na =  ");n_Print(a,r);printf("\n");
    853     //gmp_printf("\nb =  %Zd",b);n_Print(b,r);printf("\n");
    854     //printf("\nc =  ");n_Print(a,r);printf("\n");
    855     //gmp_printf("\nc =  %Zd",u->z);
     842    /*mpz_t dummy;
     843    mpz_init(dummy);
     844    mpz_fdiv_q(dummy, aa->z, b->z);
     845    mpz_mul(dummy, dummy, b->z);
     846    mpz_add(dummy, dummy, u->z);
     847    if(mpz_cmp(dummy,aa->z) != 0)
     848    {
     849        printf("\nERROR longrat:911\n");
     850        printf("\na = ");n_Print(aa,r);
     851        gmp_printf("\ndummy = %Zd",dummy);
     852        mpz_clear(dummy);mpz_init(dummy);mpz_tdiv_q(dummy, a->z, b->z);
     853        gmp_printf("\na div b = %Zd\n u = ", dummy);
     854        n_Print(u,r);
     855    }
     856    mpz_clear(dummy);*/
     857    if (aa!=NULL)
     858    {
     859      mpz_clear(aa->z);
     860    #if defined(LDEBUG)
     861      aa->debug=654324;
     862    #endif
     863      FREE_RNUMBER(aa);
     864    }
    856865    u=nlShort3(u);
    857866    nlTest(u,r);
     
    871880  u->s = 3;
    872881  mpz_mod(u->z,a->z,b->z);
    873   //printf("\nnlIntMod mpz_t\n");
    874   //gmp_printf("\na =  %Zd\n",a);
    875   //n_Print(b, r);
    876   //gmp_printf("\nb =  %Zd\n",b);
    877   //gmp_printf("\nc =  %Zd\n",u);
    878   if (bb!=NULL)
    879   {
    880     mpz_clear(bb->z);
    881 #if defined(LDEBUG)
    882     bb->debug=654324;
    883 #endif
    884     FREE_RNUMBER(bb);
    885   }
    886882  if (mpz_isNeg(u->z))
    887883  {
     
    891887      mpz_add(u->z,u->z,b->z);
    892888  }
     889  if (bb!=NULL)
     890  {
     891    mpz_clear(bb->z);
     892#if defined(LDEBUG)
     893    bb->debug=654324;
     894#endif
     895    FREE_RNUMBER(bb);
     896  }
     897  /*mpz_t dummy;
     898  mpz_init(dummy);
     899    mpz_fdiv_q(dummy, a->z, b->z);
     900    mpz_mul(dummy, dummy, b->z);
     901    mpz_add(dummy, dummy, u->z);
     902    if(mpz_cmp(dummy,a->z) != 0)
     903    {
     904        printf("\nERROR longrat:911\n");
     905        printf("\na = ");n_Print(a,r);
     906        gmp_printf("\ndummy = %Zd",dummy);
     907        mpz_clear(dummy);mpz_init(dummy);mpz_tdiv_q(dummy, a->z, b->z);
     908        gmp_printf("\na div b = %Zd\n u = ", dummy);
     909        n_Print(u,r);
     910    }
     911    mpz_clear(dummy);*/
    893912  u=nlShort3(u);
    894913  nlTest(u,r);
Note: See TracChangeset for help on using the changeset viewer.