Changeset 2b76ff in git for factory/NTLconvert.cc


Ignore:
Timestamp:
Feb 28, 2012, 12:05:03 PM (11 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '7725b5cfc1eaf99630826ecc59f559d3b6831c24')
Children:
67ed7453c29d77d1c838dfcc5a2cc5ad7b629695
Parents:
f89fed03fe4889f0b8358d3a5166851c2e87ad50
git-author:
Martin Lee <martinlee84@web.de>2012-02-28 12:05:03+01:00
git-committer:
Martin Lee <martinlee84@web.de>2012-04-04 14:42:26+02:00
Message:
chg: conversion of NTL ZZ to CanonicalForm
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/NTLconvert.cc

    rf89fed r2b76ff  
    532532////////////////////////////////////////////////////////////////////////////////
    533533
    534 static char *cf_stringtemp;
     534static unsigned char *cf_stringtemp;
     535static unsigned long cf_stringtemp_l=0L;
     536CanonicalForm
     537convertZZ2CF (ZZ a)
     538{
     539  long coeff_long=to_long(a);
     540
     541  CanonicalForm result;
     542  if ( (NumBits(a)<((long)NTL_ZZ_NBITS))
     543  && (coeff_long>((long)MINIMMEDIATE))
     544  && (coeff_long<((long)MAXIMMEDIATE)))
     545  {
     546    return CanonicalForm(coeff_long);
     547  }
     548  else
     549  {
     550    long sizeofrep= ((long *) a.rep) [1];
     551    bool lessZero= false;
     552    if (sizeofrep < 0)
     553    {
     554      lessZero= true;
     555      sizeofrep= -sizeofrep;
     556    }
     557    if (cf_stringtemp_l == 0)
     558    {
     559      cf_stringtemp_l= sizeofrep*sizeof(mp_limb_t)*2;
     560      cf_stringtemp= (unsigned char*) Alloc (cf_stringtemp_l);
     561    }
     562    else if (cf_stringtemp_l < sizeofrep*sizeof(mp_limb_t)*2)
     563    {
     564      Free (cf_stringtemp, cf_stringtemp_l);
     565      cf_stringtemp_l= sizeofrep*sizeof(mp_limb_t)*2;
     566      cf_stringtemp= (unsigned char*) Alloc (cf_stringtemp_l);
     567    }
     568    int cc= mpn_get_str (cf_stringtemp, 16, (mp_limb_t *) (((long *) (a.rep)) + 2), sizeofrep);
     569
     570    char* cf_stringtemp2;
     571    if (lessZero)
     572    {
     573      cf_stringtemp2= new char [cc + 2];
     574      cf_stringtemp2[0]='-';
     575      for (int j= 1; j <= cc; j++)
     576        cf_stringtemp2[j]= IntValToChar ((int) cf_stringtemp [j-1]);
     577      cf_stringtemp2[cc+1]='\0';
     578    }
     579    else
     580    {
     581      cf_stringtemp2= new char [cc + 1];
     582      for (int j= 0; j < cc; j++)
     583        cf_stringtemp2[j]= IntValToChar ((int) cf_stringtemp [j]);
     584      cf_stringtemp2[cc]='\0';
     585    }
     586
     587    result= CanonicalForm (cf_stringtemp2, 16);
     588    delete [] cf_stringtemp2;
     589    return result;
     590  }
     591  return result;
     592}
     593
     594/*static char *cf_stringtemp;
    535595static char *cf_stringtemp2;
    536596static int cf_stringtemp_l=0;
     
    629689  return CanonicalForm(cf_stringtemp2,16);
    630690  //return tmp;
    631 }
     691}*/
    632692
    633693////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.