Changeset 41e8b3 in git for libpolys/coeffs


Ignore:
Timestamp:
Feb 20, 2013, 10:00:15 AM (11 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
a8941bc5ad99f3a4f45b89d94742e879b338a1e0
Parents:
5e42ec33c5a0d777cb71dc36d36924181f7d88b3fb875f17b84670badc10fae02dcd7870b46005c2
Message:
Merge pull request #285 from mmklee/fix_sw

fix: interchanged dst and src
Location:
libpolys/coeffs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/ffields.cc

    r5e42ec r41e8b3  
    813813    }
    814814  }
    815   if (nCoeff_is_Zp(src,src->m_nfCharP))
     815  if (nCoeff_is_Zp(src,dst->m_nfCharP))
    816816  {
    817817    return nfMapP;    /* Z/p -> GF(p,n) */
  • libpolys/coeffs/shortfl.cc

    rfb875f1 r41e8b3  
    66* ABSTRACT:
    77*/
    8 
     8#include <iostream>
    99#include <coeffs/shortfl.h>
    1010
    1111#include <string.h>
     12#include <math.h>
    1213#include <coeffs/coeffs.h>
    1314#include <coeffs/numbers.h>
     
    373374  assume( getCoeffType(r) == ID );
    374375  assume( getCoeffType(aRing) ==  n_Zp );
    375  
     376
    376377  int i = (int)((long)from);
    377378  float f = (float)i;
     
    389390
    390391static number nrMapC(number from, const coeffs aRing, const coeffs r)
    391 { 
     392{
    392393  assume( getCoeffType(r) == ID );
    393394  assume( getCoeffType(aRing) == n_long_C );
    394  
     395
    395396  gmp_float h = ((gmp_complex*)from)->real();
    396397  float t =(float)mpf_get_d((mpf_srcptr)&h);
     
    406407*/
    407408#define SR_HDL(A) ((long)(A))
    408 #define mpz_isNeg(A) ((A)->_mp_size<0)
    409 #define mpz_limb_size(A) ((A)->_mp_size)
    410 #define mpz_limb_d(A) ((A)->_mp_d)
    411 #define MPZ_DIV(A,B,C) mpz_tdiv_q((A),(B),(C))
    412409#define IS_INT(A) ((A)->s==3)
    413410#define IS_IMM(A) (SR_HDL(A)&SR_INT)
    414411#define GET_NOM(A) ((A)->z)
    415412#define GET_DENOM(A) ((A)->n)
    416 #define MPZ_INIT mpz_init
    417 #define MPZ_CLEAR mpz_clear
    418413
    419414  assume( getCoeffType(r) == ID );
    420415  assume( getCoeffType(aRing) == n_Q );
    421 
    422   mpz_t h;
    423   mpz_ptr g,z,n;
    424   int i,j,t,s;
    425   float ba,rr,rn,y;
    426416
    427417  if (IS_IMM(from))
    428418    return nf((float)nlInt(from,NULL /* dummy for nlInt*/)).N();
    429   z=GET_NOM(from);
    430   s=0X10000;
    431   ba=(float)s;
    432   ba*=ba;
    433   rr=0.0;
    434   i=mpz_size1(z);
     419
     420  /* read out the enumerator */
     421  mpz_ptr z=GET_NOM(from);
     422  if(mpz_size1(z)>4)
     423  {
     424    WerrorS("float overflow");
     425    return nf(0.0).N();
     426  }
     427  mpf_t e;
     428  mpf_init(e);
     429  mpf_set_z(e,z);
     430
     431  /* if number was an integer, we are done*/
    435432  if(IS_INT(from))
    436433  {
    437     if(i>4)
    438     {
    439       WerrorS("float overflow");
    440       return nf(rr).N();
    441     }
    442     i--;
    443     rr=(float)mpz_limb_d(z)[i];
    444     while(i>0)
    445     {
    446       i--;
    447       y=(float)mpz_limb_d(z)[i];
    448       rr=rr*ba+y;
    449     }
    450     if(mpz_isNeg(z))
    451       rr=-rr;
    452     return nf(rr).N();
    453   }
    454   n=GET_DENOM(from);
    455   j=s=mpz_limb_size(n);
    456   if(j>i)
    457   {
    458     g=n; n=z; z=g;
    459     t=j; j=i; i=t;
    460   }
    461   t=i-j;
    462   if(t>4)
    463   {
    464     if(j==s)
    465       WerrorS("float overflow");
    466     return nf(rr).N();
    467   }
    468   if(t>1)
    469   {
    470     g=h;
    471     MPZ_INIT(g);
    472     MPZ_DIV(g,z,n);
    473     t=mpz_size1(g);
    474     if(t>4)
    475     {
    476       MPZ_CLEAR(g);
    477       if(j==s)
    478         WerrorS("float overflow");
    479       return nf(rr).N();
    480     }
    481     t--;
    482     rr=(float)mpz_limb_d(g)[t];
    483     while(t)
    484     {
    485       t--;
    486       y=(float)mpz_limb_d(g)[t];
    487       rr=rr*ba+y;
    488     }
    489     MPZ_CLEAR(g);
    490     if(j!=s)
    491       rr=1.0/rr;
    492     if(mpz_isNeg(z))
    493       rr=-rr;
    494     return nf(rr).N();
    495   }
    496   rn=(float)mpz_limb_d(n)[j-1];
    497   rr=(float)mpz_limb_d(z)[i-1];
    498   if(j>1)
    499   {
    500     rn=rn*ba+(float)mpz_limb_d(n)[j-2];
    501     rr=rr*ba+(float)mpz_limb_d(z)[i-2];
    502     i--;
    503   }
    504   if(t!=0)
    505     rr=rr*ba+(float)mpz_limb_d(z)[i-2];
    506   if(j==s)
    507     rr=rr/rn;
    508   else
    509     rr=rn/rr;
    510   if(mpz_isNeg(z))
    511     rr=-rr;
    512   return nf(rr).N();
    513 }
    514 
     434    double basis;
     435    signed long int exp;
     436    basis = mpf_get_d_2exp(&exp, e);
     437    float f = ldexp(basis,exp);
     438    mpf_clear(e);
     439    return nf(f).N();
     440  }
     441
     442  /* else read out the denominator */
     443  mpz_ptr n = GET_DENOM(from);
     444  if(mpz_size1(n)>4)
     445  {
     446    WerrorS("float overflow");
     447    mpf_clear(e);
     448    return nf(0.0).N();
     449  }
     450  mpf_t d;
     451  mpf_init(d);
     452  mpf_set_z(d,n);
     453
     454  /* and compute the quotient */
     455  mpf_t q;
     456  mpf_init(q);
     457  mpf_div(q,e,d);
     458
     459  double basis;
     460  signed long int exp;
     461  basis = mpf_get_d_2exp(&exp, q);
     462  float f = ldexp(basis,exp);
     463  mpf_clear(e);
     464  mpf_clear(d);
     465  mpf_clear(q);
     466  return nf(f).N();
     467}
    515468
    516469nMapFunc nrSetMap(const coeffs src, const coeffs dst)
     
    544497{
    545498  assume( getCoeffType(n) == ID );
    546    
     499
    547500  assume( p == NULL );
    548    
     501
    549502  n->cfKillChar = ndKillChar; /* dummy */
    550503  n->ch = 0;
     
    578531  n->cfDBTest=ndDBTest; // not yet implemented: nrDBTest;
    579532#endif
    580  
     533
    581534  n->nCoeffIsEqual = ndCoeffIsEqual;
    582535
    583536  n->float_len = SHORT_REAL_LENGTH;
    584537  n->float_len2 = SHORT_REAL_LENGTH;
    585    
     538
    586539  // TODO: Any variables?
    587540  return FALSE;
Note: See TracChangeset for help on using the changeset viewer.