Changeset 09da99 in git for ntl/include


Ignore:
Timestamp:
Nov 3, 2003, 6:33:49 PM (20 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '4a9821a93ffdc22a6696668bd4f6b8c9de3e6c5f')
Children:
70fea801cbe08a22d1b0e9d8d1d410144e0e91f6
Parents:
be2bb37dcbd03b120f14559d378b21b104d907c4
Message:
*hannes: NTL- 5.3.1


git-svn-id: file:///usr/local/Singular/svn/trunk@6910 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
ntl/include/NTL
Files:
1 added
29 edited

Legend:

Unmodified
Added
Removed
  • ntl/include/NTL/FFT.h

    rbe2bb3 r09da99  
    99NTL_OPEN_NNS
    1010
    11 #define NTL_FFTFudge (3)
     11#define NTL_FFTFudge (4)
    1212// This constant is used in selecting the correct
    1313// number of FFT primes for polynomial multiplication
    14 // in ZZ_pX and zz_pX.  Set at 3, this allows for
     14// in ZZ_pX and zz_pX.  Set at 4, this allows for
    1515// two FFT reps to be added or subtracted once,
    16 // before performing CRT.
    17 // Don't change this.
     16// before performing CRT, and leaves a reasonable margin for error.
     17// Don't change this!
    1818
    1919#define NTL_FFTMaxRootBnd (NTL_SP_NBITS-2)
    2020// Absolute maximum root bound for FFT primes.
    21 // Don't change this.
     21// Don't change this!
    2222
    2323#if (25 <= NTL_FFTMaxRootBnd)
  • ntl/include/NTL/GF2.h

    rbe2bb3 r09da99  
    2323GF2& operator=(long a) { _GF2__rep = a & 1; return *this; }
    2424
     25static long modulus() { return 2; }
     26static GF2 zero() { return GF2(); }
     27
    2528};
    2629
     
    3538inline long rep(GF2 a) { return a._GF2__rep; }
    3639
    37 static long modulus() { return 2; }
    38 static GF2 zero() { return GF2(); }
    3940
    4041inline void clear(GF2& x) { x._GF2__rep = 0; }
  • ntl/include/NTL/GF2E.h

    rbe2bb3 r09da99  
    116116static long WordLength() { return GF2EInfo->p.WordLength(); }
    117117
     118static long storage() { return WV_storage(GF2E::WordLength()); }
     119
    118120static const GF2XModulus& modulus() { return GF2EInfo->p; }
    119121
     
    134136
    135137
    136 // read-only access to _GF2E__representation
     138// read-only access to GF2E representation
    137139inline const GF2X& rep(const GF2E& a) { return a._GF2E__rep; }
    138140
     
    433435
    434436
    435 // ****** input/output
    436437
    437438inline GF2E& GF2E::operator=(long a) { conv(*this, a); return *this; }
  • ntl/include/NTL/GF2EX.h

    rbe2bb3 r09da99  
    7676
    7777
    78 /********************************************************************
    79 
    80                            input and output
    81 
    82 *********************************************************************/
    83 
    84 
    8578/**********************************************************
    8679
     
    698691
    699692NTL_eq_vector_decl(GF2EX,vec_GF2EX)
     693
    700694
    701695
  • ntl/include/NTL/RR.h

    rbe2bb3 r09da99  
    233233
    234234
     235// routines with a precision parameter
     236
     237void ConvPrec(RR& z, const RR& a, long p);
     238inline RR ConvPrec(const RR& a, long p)
     239   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     240
     241void AddPrec(RR& z, const RR& a, const RR& b, long p);
     242inline RR AddPrec(const RR& a, const RR& b, long p)
     243   { RR z; AddPrec(z, a, b, p); NTL_OPT_RETURN(RR, z); }
     244
     245void SubPrec(RR& z, const RR& a, const RR& b, long p);
     246inline RR SubPrec(const RR& a, const RR& b, long p)
     247   { RR z; SubPrec(z, a, b, p); NTL_OPT_RETURN(RR, z); }
     248
     249void NegatePrec(RR& z, const RR& a, long p);
     250inline RR NegatePrec(const RR& a, long p)
     251   { RR z; NegatePrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     252
     253void AbsPrec(RR& z, const RR& a, long p);
     254inline RR AbsPrec(const RR& a, long p)
     255   { RR z; AbsPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     256
     257void MulPrec(RR& z, const RR& a, const RR& b, long p);
     258inline RR MulPrec(const RR& a, const RR& b, long p)
     259   { RR z; MulPrec(z, a, b, p); NTL_OPT_RETURN(RR, z); }
     260
     261void SqrPrec(RR& z, const RR& a, long p);
     262inline RR SqrPrec(const RR& a, long p)
     263   { RR z; SqrPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     264
     265void DivPrec(RR& z, const RR& a, const RR& b, long p);
     266inline RR DivPrec(const RR& a, const RR& b, long p)
     267   { RR z; DivPrec(z, a, b, p); NTL_OPT_RETURN(RR, z); }
     268
     269void InvPrec(RR& z, const RR& a, long p);
     270inline RR InvPrec(const RR& a, long p)
     271   { RR z; InvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     272
     273void SqrRootPrec(RR& z, const RR& a, long p);
     274inline RR SqrRootPrec(const RR& a, long p)
     275   { RR z; SqrRootPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     276
     277void TruncPrec(RR& z, const RR& a, long p);
     278inline RR TruncPrec(const RR& a, long p)
     279   { RR z; TruncPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     280
     281void FloorPrec(RR& z, const RR& a, long p);
     282inline RR FloorPrec(const RR& a, long p)
     283   { RR z; FloorPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     284
     285void CeilPrec(RR& z, const RR& a, long p);
     286inline RR CeilPrec(const RR& a, long p)
     287   { RR z; CeilPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     288
     289void RoundPrec(RR& z, const RR& a, long p);
     290inline RR RoundPrec(const RR& a, long p)
     291   { RR z; RoundPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     292
     293void ConvPrec(RR& z, const ZZ& a, long p);
     294inline RR ConvPrec(const ZZ& a, long p)
     295   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     296
     297void ConvPrec(RR& z, long a, long p);
     298inline RR ConvPrec(long a, long p)
     299   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     300
     301inline void ConvPrec(RR& z, int a, long p) { ConvPrec(z, long(a), p); }
     302inline RR ConvPrec(int a, long p)
     303   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     304
     305void ConvPrec(RR& z, unsigned long a, long p);
     306inline RR ConvPrec(unsigned long a, long p)
     307   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     308
     309inline void ConvPrec(RR& z, unsigned int a, long p)
     310   { ConvPrec(z, (unsigned long)(a), p); }
     311inline RR ConvPrec(unsigned int a, long p)
     312   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     313
     314void ConvPrec(RR& z, double a, long p);
     315inline RR ConvPrec(double a, long p)
     316   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     317
     318void ConvPrec(RR& z, const xdouble& a, long p);
     319inline RR ConvPrec(const xdouble& a, long p)
     320   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     321
     322void ConvPrec(RR& z, const quad_float& a, long p);
     323inline RR ConvPrec(const quad_float& a, long p)
     324   { RR z; ConvPrec(z, a, p); NTL_OPT_RETURN(RR, z); }
     325
     326void ConvPrec(RR& z, const char *s, long p);
     327inline RR ConvPrec(const char *s, long p)
     328   { RR z; ConvPrec(z, s, p); NTL_OPT_RETURN(RR, z); }
     329
     330void MakeRRPrec(RR& z, const ZZ& a, long e, long p);
     331inline RR MakeRRPrec(const ZZ& a, long e, long p)
     332   { RR z; MakeRRPrec(z, a, e, p); NTL_OPT_RETURN(RR, z); }
     333
     334
     335
     336
     337
     338
    235339void conv(RR& z, const ZZ& a);
    236340void conv(RR& z, long a);
     
    335439   { RR z; power2(z, e); NTL_OPT_RETURN(RR, z); }
    336440
     441
    337442void SqrRoot(RR& x, const RR& a);
    338443inline RR SqrRoot(const RR& a)
  • ntl/include/NTL/WordVector.h

    rbe2bb3 r09da99  
    55/**************************************************************
    66
    7   A WordVector is essentially functionally similar to
     7  A WordVector is functionally similar to
    88  a  generic NTL vector of _ntl_ulong. 
    99
     
    123123   { WordVector::append_impl(v, w); }
    124124
     125
    125126long operator==(const WordVector& a, const WordVector& b); 
    126127long operator!=(const WordVector& a, const WordVector& b);
     
    133134
    134135
     136long WV_BlockConstructAlloc(WordVector& x, long d, long n);
     137 
     138void WV_BlockConstructSet(WordVector& x, WordVector& y, long i);
     139 
     140long WV_BlockDestroy(WordVector& x);
     141
     142long WV_storage(long d);
     143
     144
     145
     146
     147
    135148NTL_CLOSE_NNS
    136149
  • ntl/include/NTL/ZZ.h

    rbe2bb3 r09da99  
    180180inline long to_long(const ZZ& a)  { return NTL_ztoint(a.rep); }
    181181
    182 inline void conv(int& x, const ZZ& a) { x = int(NTL_ztoint(a.rep)); }
    183 inline int to_int(const ZZ& a)  { return int(NTL_ztoint(a.rep)); }
     182inline void conv(int& x, const ZZ& a)
     183   { unsigned int res = (unsigned int) NTL_ztouint(a.rep);
     184     x = NTL_UINT_TO_INT(res); }
     185
     186inline int to_int(const ZZ& a) 
     187   { unsigned int res = (unsigned int) NTL_ztouint(a.rep);
     188     return NTL_UINT_TO_INT(res); }
    184189
    185190inline void conv(unsigned long& x, const ZZ& a) { x = NTL_ztouint(a.rep); }
    186 inline long to_ulong(const ZZ& a)  { return NTL_ztouint(a.rep); }
     191inline unsigned long to_ulong(const ZZ& a)  { return NTL_ztouint(a.rep); }
    187192
    188193inline void conv(unsigned int& x, const ZZ& a)
     
    11921197
    11931198
    1194 
    1195 
    1196 /**************************************************************
    1197 
    1198                       Input/Output
    1199 
    1200 ***************************************************************/
    1201 
    1202 
    12031199/****************************************************************
    12041200
     
    12211217{
    12221218   long res = a + b;
    1223 #if (NTL_ARITH_RIGHT_SHIFT && defined(NTL_AVOID_BRANCHING))
     1219#if (NTL_ARITH_RIGHT_SHIFT && defined(NTL_AVOID_BRANCHING) && !defined(NTL_CLEAN_INT))
    12241220   res -= n;
    12251221   res += (res >> (NTL_BITS_PER_LONG-1)) & n;
     
    12381234{
    12391235   long res = a - b;
    1240 #if (NTL_ARITH_RIGHT_SHIFT && defined(NTL_AVOID_BRANCHING))
     1236#if (NTL_ARITH_RIGHT_SHIFT && defined(NTL_AVOID_BRANCHING) && !defined(NTL_CLEAN_INT))
    12411237   res += (res >> (NTL_BITS_PER_LONG-1)) & n;
    12421238   return res;
     
    14641460
    14651461
    1466 
    1467 
    1468 #else
     1462#elif (!defined(NTL_CLEAN_INT))
    14691463
    14701464inline long MulMod(long a, long b, long n)
     
    15441538}
    15451539
     1540#else
     1541
     1542/*
     1543 * NTL_CLEAN_INT set: these versions of MulMod are completely portable,
     1544 * assuming IEEE floating point arithmetic.
     1545 */
     1546
     1547inline long MulMod(long a, long b, long n)
     1548{
     1549   long q;
     1550   unsigned long res;
     1551
     1552   q  = (long) ((((double) a) * ((double) b)) / ((double) n));
     1553
     1554   res = ((unsigned long) a)*((unsigned long) b) -
     1555         ((unsigned long) q)*((unsigned long) n);
     1556
     1557   if (res >> (NTL_BITS_PER_LONG-1))
     1558      res += n;
     1559   else if (((long) res) >= n)
     1560      res -= n;
     1561 
     1562   return ((long) res);
     1563}
     1564
     1565inline long MulMod(long a, long b, long n, double ninv)
     1566{
     1567   long q;
     1568   unsigned long res;
     1569
     1570   q  = (long) ((((double) a) * ((double) b)) * ninv);
     1571
     1572   res = ((unsigned long) a)*((unsigned long) b) -
     1573         ((unsigned long) q)*((unsigned long) n);
     1574
     1575   if (res >> (NTL_BITS_PER_LONG-1))
     1576      res += n;
     1577   else if (((long) res) >= n)
     1578      res -= n;
     1579 
     1580   return ((long) res);
     1581}
     1582
     1583
     1584inline long MulMod2(long a, long b, long n, double bninv)
     1585{
     1586   long q;
     1587   unsigned long res;
     1588
     1589   q  = (long) (((double) a) * bninv);
     1590
     1591   res = ((unsigned long) a)*((unsigned long) b) -
     1592         ((unsigned long) q)*((unsigned long) n);
     1593
     1594   if (res >> (NTL_BITS_PER_LONG-1))
     1595      res += n;
     1596   else if (((long) res) >= n)
     1597      res -= n;
     1598 
     1599   return ((long) res);
     1600}
     1601
     1602inline long MulDivRem(long& qq, long a, long b, long n, double bninv)
     1603{
     1604   long q;
     1605   unsigned long res;
     1606
     1607   q  = (long) (((double) a) * bninv);
     1608   res = ((unsigned long) a)*((unsigned long) b) -
     1609         ((unsigned long) q)*((unsigned long) n);
     1610
     1611   if (res >> (NTL_BITS_PER_LONG-1)) {
     1612      res += n;
     1613      q--;
     1614   } else if (((long) res) >= n) {
     1615      res -= n;
     1616      q++;
     1617   }
     1618
     1619   qq = q;
     1620   return ((long) res);
     1621}
     1622
    15461623
    15471624#endif
  • ntl/include/NTL/ZZX.h

    rbe2bb3 r09da99  
    7474
    7575
    76 
    77 
    78 /********************************************************************
    79 
    80                            input and output
    81 
    82 I/O format:
    83 
    84    [a_0 a_1 ... a_n],
    85 
    86 represents the polynomial a_0 + a_1*X + ... + a_n*X^n.
    87 
    88 On output, all coefficients will be integers between 0 and p-1,
    89 amd a_n not zero (the zero polynomial is [ ]).
    90 Leading zeroes are stripped.
    91 
    92 *********************************************************************/
    9376
    9477
  • ntl/include/NTL/ZZ_p.h

    rbe2bb3 r09da99  
    1010
    1111
    12 // _ZZ_p__representation:  each ZZ_p is represented by a ZZ in the range 0..p-1.
     12// ZZ_p representation:  each ZZ_p is represented by a ZZ in the range 0..p-1.
    1313
    1414// The constructor for a ZZ_p pre-allocates space for the underlying ZZ,
     
    420420
    421421
    422 // ****** input/output
    423 
    424422inline ZZ_p& ZZ_p::operator=(long a) { conv(*this, a); return *this; }
    425423
  • ntl/include/NTL/ZZ_pE.h

    rbe2bb3 r09da99  
    353353
    354354
    355 // ****** input/output
    356355inline ZZ_pE& ZZ_pE::operator=(long a) { conv(*this, a); return *this; }
    357356inline ZZ_pE& ZZ_pE::operator=(const ZZ_p& a) { conv(*this, a); return *this; }
  • ntl/include/NTL/ZZ_pX.h

    rbe2bb3 r09da99  
    170170
    171171long IsX(const ZZ_pX& a);
    172 // test if x = X
     172// test if a = X
    173173
    174174inline void clear(ZZ_pX& x)
     
    995995NTL_eq_vector_decl(ZZ_pX,vec_ZZ_pX)
    996996
    997 
    998997/**********************************************************
    999998
  • ntl/include/NTL/c_lip.h

    rbe2bb3 r09da99  
    66
    77#if (defined(NTL_AVOID_FLOAT) || defined(NTL_LONG_LONG))
    8 #error "at most one of -DNTL_SINGLE_MUL -DNTL_AVOID_FLOAT -DNTL_LONG_LONG allowed"
     8#error "at most one of NTL_SINGLE_MUL NTL_AVOID_FLOAT NTL_LONG_LONG allowed"
    99#endif
    1010
    1111#elif (defined(NTL_AVOID_FLOAT) && defined(NTL_LONG_LONG))
    12 #error "at most one of -DNTL_SINGLE_MUL -DNTL_AVOID_FLOAT -DNTL_LONG_LONG allowed"
     12#error "at most one of NTL_SINGLE_MUL NTL_AVOID_FLOAT NTL_LONG_LONG allowed"
    1313#endif
    1414
     
    1818#error "NTL_SINGLE_MUL not supported on this platform"
    1919#endif
     20
     21#if (defined(NTL_CLEAN_INT))
     22#error "NTL_SINGLE_MUL not allowed with NTL_CLEAN_INT"
     23#endif
     24
    2025
    2126#define NTL_NBITS (26)
     
    412417   (except for the exponent in exponentiation) and results are in the
    413418   range [0, n-1].   
    414 
    415    ALIAS RESTRICTION:  output parameters should not alias n
    416419
    417420***********************************************************************/
  • ntl/include/NTL/def_config.h

    rbe2bb3 r09da99  
    5050  * they must be set by hand, before installation begins.
    5151  */
     52
    5253
    5354#if 0
     
    201202#endif
    202203
     204#if 0
     205#define NTL_CLEAN_INT
     206
     207/*
     208 *   This will disallow the use of some non-standard integer arithmetic
     209 *   that may improve performance somewhat.
     210 *
     211 *   To re-build after changing this flag: rm *.o; make ntl.a
     212 */
     213
     214#endif
     215
     216#if 0
     217#define NTL_CLEAN_PTR
     218
     219/*
     220 *   This will disallow the use of some non-standard pointer arithmetic
     221 *   that may improve performance somewhat.
     222 *
     223 *   To re-build after changing this flag: rm *.o; make ntl.a
     224 */
     225
     226#endif
     227
    203228 
    204229#if 0
     
    278303 * arithmetic: the default, NTL_LONG_LONG, NTL_AVOID_FLOAT, or NTL_SINGLE_MUL.
    279304 * The configuration wizard will choose among the first three; the use of
    280  * NTL_SINGLE_MUL is not generally recommended.
    281  *   
     305 * NTL_SINGLE_MUL is only allowed if NTL_CLEAN_INT is not set, and its
     306 * use is not recommended.
     307 *
    282308 * These flags are irrelevant when NTL_GMP_LIP is set, and are simply ignored,
    283309 * except for NTL_SINGLE_MUL -- setting that causes a complie-time error.
  • ntl/include/NTL/fileio.h

    rbe2bb3 r09da99  
    1414#endif
    1515
    16 NTL_OPEN_NNS
    17 
    18 
    19 // opens file for reading
    20 
    21 char *FileName(const char* stem, const char *ext);
    22 
    23 // builds the name "stem.ext"
    24 
    25 char *FileName(const char* stem, const char *ext, long d);
    26 
    27 // builds the name stem.ext.d
    28 
    29 NTL_CLOSE_NNS
    30 
    3116#endif
    3217
  • ntl/include/NTL/lzz_p.h

    rbe2bb3 r09da99  
    342342
    343343
    344 // ****** input/output
    345 
    346344NTL_CLOSE_NNS
    347345
  • ntl/include/NTL/lzz_pE.h

    rbe2bb3 r09da99  
    349349
    350350
    351 // ****** input/output
    352351inline const zz_pX& rep(const zz_pE& a) { return a._zz_pE__rep; }
    353352
  • ntl/include/NTL/lzz_pEX.h

    rbe2bb3 r09da99  
    6161
    6262};
     63
     64
    6365
    6466
     
    707709
    708710
    709 
    710711/*******************************************************
    711712
  • ntl/include/NTL/lzz_pX.h

    rbe2bb3 r09da99  
    128128*********************************************************************/
    129129
     130
     131
    130132/**********************************************************
    131133
     
    983985
    984986NTL_eq_vector_decl(zz_pX,vec_zz_pX)
     987
    985988
    986989
  • ntl/include/NTL/mach_desc.h

    rbe2bb3 r09da99  
    77#define NTL_MAX_INT (2147483647)
    88#define NTL_BITS_PER_INT (32)
     9#define NTL_BITS_PER_SIZE_T (32)
    910#define NTL_ARITH_RIGHT_SHIFT (1)
    1011#define NTL_NBITS_MAX (30)
  • ntl/include/NTL/mat_GF2.h

    rbe2bb3 r09da99  
    4646
    4747   long position(const vec_GF2& a) const { return _mat_GF2__rep.position(a); }
     48   long position1(const vec_GF2& a) const { return _mat_GF2__rep.position1(a); }
    4849 
    4950   mat_GF2(mat_GF2& x, INIT_TRANS_TYPE)  :
     
    5152}; 
    5253 
    53 inline const vec_vec_GF2& _mat_GF2__rep(const mat_GF2& a) 
     54inline const vec_vec_GF2& rep(const mat_GF2& a) 
    5455   { return a._mat_GF2__rep; } 
    5556
     
    6566long operator==(const mat_GF2& a, const mat_GF2& b);
    6667long operator!=(const mat_GF2& a, const mat_GF2& b);
     68
    6769
    6870void add(mat_GF2& X, const mat_GF2& A, const mat_GF2& B);
  • ntl/include/NTL/matrix.h

    rbe2bb3 r09da99  
    4444  \
    4545   long position(const vec_T& l__a) const { return _mat__rep.position(l__a); } \
     46   long position1(const vec_T& l__a) const { return _mat__rep.position1(l__a); } \
    4647  mat_T(mat_T& l__x, NTL_NNS INIT_TRANS_TYPE) :  \
    4748    _mat__rep(l__x._mat__rep, NTL_NNS INIT_TRANS), _mat__numcols(l__x._mat__numcols) { }  \
     
    6061long operator==(const mat_T& l__a, const mat_T& l__b); \
    6162long operator!=(const mat_T& l__a, const mat_T& l__b); \
     63
    6264
    6365
     
    169171
    170172
     173
    171174#endif
  • ntl/include/NTL/new.h

    rbe2bb3 r09da99  
    55#include <NTL/config.h>
    66
     7#if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NTN))
     8
     9// We use <new> and std::nothrow, even if neither NTL_STD_CXX nor 
     10// NTL_PSTD_NHF are set.  This appears to be somewhat more compatible
     11// with current compilers.
     12
     13#include <new>
     14
     15#define NTL_NEW_OP new (std::nothrow)
     16
     17
     18#else
     19
    720#define NTL_NEW_OP new
    821
    922#endif
     23
     24#endif
  • ntl/include/NTL/pair.h

    rbe2bb3 r09da99  
    2222
    2323
     24
    2425#define NTL_pair_eq_decl(S,T,pair_S_T)  \
    2526inline long operator==(const pair_S_T& l__x, const pair_S_T& l__y)  \
  • ntl/include/NTL/quad_float.h

    rbe2bb3 r09da99  
    222222
    223223
     224
    224225quad_float sqrt(const quad_float&);
    225226quad_float floor(const quad_float&);
     
    238239
    239240long to_long(const quad_float&);
    240 inline int to_int(const quad_float& x) { return int(to_long(x)); }
     241inline int to_int(const quad_float& x) { return to_int(to_long(x)); }
    241242
    242243inline double to_double(const quad_float& x) { return x.hi; }
  • ntl/include/NTL/tools.h

    rbe2bb3 r09da99  
    33#define NTL_tools__H
    44
    5 #include <NTL/config.h>
    6 #include <NTL/mach_desc.h>
     5#include <NTL/ctools.h>
     6
     7#if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NHF))
     8
     9// new header files
     10
     11#include <cstdlib>
     12#include <cmath>
     13
     14#else
     15
     16// old header files
    717
    818#include <stdlib.h>
    919#include <math.h>
     20
     21#endif
    1022
    1123#if (defined(NTL_STD_CXX) || defined(NTL_PSTD_NHF))
     
    6880
    6981#if 0
     82
     83// This is for debugging purposes only.
     84
    7085namespace foo_bar {
     86
     87class ostream;
     88class istream;
    7189
    7290typedef unsigned int size_t;
     
    7997
    8098
    81 #include <NTL/IsFinite.h>
    8299
    83100#if (!defined(NTL_CXX_ONLY))
     
    146163inline void swap(int& a, int& b)  {  int t;  t = a; a = b; b = t; }
    147164
     165
     166
    148167inline void conv(int& x, int a) { x = a; }
    149 inline void conv(int& x, long a) { x = int(a); }
     168inline void conv(int& x, long a)
     169   { unsigned y = (unsigned) a;  x = NTL_UINT_TO_INT(y); }
    150170inline void conv(int& x, float a) { x = int(NTL_SNS floor(double(a))); }
    151171inline void conv(int& x, double a) { x = int(NTL_SNS floor(a)); }
    152172
     173inline void conv(int& x, unsigned a)
     174   { x = NTL_UINT_TO_INT(a); }
     175
     176inline void conv(int& x, unsigned long a)
     177   { unsigned y = (unsigned) a;  x = NTL_UINT_TO_INT(y); }
     178
    153179inline int to_int(int a) { return a; }
    154 inline int to_int(long a) { return int(a); }
     180inline int to_int(long a)
     181   { unsigned y = (unsigned) a;  return NTL_UINT_TO_INT(y); }
    155182inline int to_int(float a) { return int(NTL_SNS floor(double(a))); }
    156183inline int to_int(double a) { return int(NTL_SNS floor(a)); }
     184
     185inline int to_int(unsigned a)
     186   { return NTL_UINT_TO_INT(a); }
     187
     188inline int to_int(unsigned long a)
     189   { unsigned y = (unsigned) a;  return NTL_UINT_TO_INT(y); }
    157190
    158191
     
    162195inline void conv(long& x, double a) { x = long(NTL_SNS floor(a)); }
    163196
     197inline void conv(long& x, unsigned a)
     198   { unsigned long y = a;  x = NTL_ULONG_TO_LONG(y); }
     199
     200inline void conv(long& x, unsigned long a)
     201   { x = NTL_ULONG_TO_LONG(a); }
     202
    164203inline long to_long(int a) { return a; }
    165204inline long to_long(long a) { return a; }
     
    167206inline long to_long(double a) { return long(NTL_SNS floor(a)); }
    168207
     208inline long to_long(unsigned a)
     209   { unsigned long y = a;  return NTL_ULONG_TO_LONG(y); }
     210
     211inline long to_long(unsigned long a)
     212   { return NTL_ULONG_TO_LONG(a); }
     213
    169214inline void conv(float& x, int a) { x = float(a); }
    170215inline void conv(float& x, long a) { x = float(a); }
     216inline void conv(float& x, unsigned a) { x = float(a); }
     217inline void conv(float& x, unsigned long a) { x = float(a); }
    171218inline void conv(float& x, float a) { x = a; }
    172219inline void conv(float& x, double a) { x = float(a); }
     
    174221inline float to_float(int a) { return float(a); }
    175222inline float to_float(long a) { return float(a); }
     223inline float to_float(unsigned a) { return float(a); }
     224inline float to_float(unsigned long a) { return float(a); }
    176225inline float to_float(float a) { return a; }
    177226inline float to_float(double a) { return float(a); }
     
    179228inline void conv(double& x, int a) { x = double(a); }
    180229inline void conv(double& x, long a) { x = double(a); }
     230inline void conv(double& x, unsigned a) { x = double(a); }
     231inline void conv(double& x, unsigned long a) { x = double(a); }
    181232inline void conv(double& x, float a) { x = double(a); }
    182233inline void conv(double& x, double a) { x = a; }
     
    184235inline double to_double(int a) { return double(a); }
    185236inline double to_double(long a) { return double(a); }
     237inline double to_double(unsigned a) { return double(a); }
     238inline double to_double(unsigned long a) { return double(a); }
    186239inline double to_double(float a) { return double(a); }
    187240inline double to_double(double a) { return a; }
    188241
     242
     243long IsWhiteSpace(long c);
     244
     245long CharToIntVal(long c);
     246char IntValToChar(long a);
     247
     248
     249
    189250void Error(const char *s);
    190251
     
    196257
    197258
     259
     260
    198261NTL_CLOSE_NNS
    199262
  • ntl/include/NTL/vec_GF2.h

    rbe2bb3 r09da99  
    7676   long length() const { return _len; }
    7777   long MaxLength() const { return _maxlen >> 1; } 
     78   long allocated() const { return rep.MaxLength() * NTL_BITS_PER_LONG; }
    7879   long fixed() const { return _maxlen & 1; }
    7980
     
    165166inline long operator!=(const vec_GF2& a, const vec_GF2& b)
    166167   { return !(a == b); }
     168
    167169void shift(vec_GF2& x, const vec_GF2& a, long n);
    168170// x = a shifted n places, i.e., if l = a.length(),
  • ntl/include/NTL/vector.h

    rbe2bb3 r09da99  
    44
    55#include <NTL/tools.h>
     6#include <stdio.h>
    67
    78struct _ntl_VectorHeader {
     
    106107   long length() const { return (!_vec__rep) ?  0 : NTL_VEC_HEAD(_vec__rep)->length; }  \
    107108   long MaxLength() const { return (!_vec__rep) ?  0 : NTL_VEC_HEAD(_vec__rep)->init; } \
     109   long allocated() const { return (!_vec__rep) ?  0 : NTL_VEC_HEAD(_vec__rep)->alloc; } \
    108110   long fixed() const { return _vec__rep && NTL_VEC_HEAD(_vec__rep)->fixed; } \
    109111  \
     
    140142   vec_T(vec_T& l__x, NTL_NNS INIT_TRANS_TYPE) { _vec__rep = l__x._vec__rep; l__x._vec__rep = 0; } \
    141143   long position(const T& l__a) const;  \
     144   long position1(const T& l__a) const;  \
    142145};  \
    143146 \
     
    148151
    149152
     153
    150154#define NTL_eq_vector_decl(T,vec_T)  \
    151155long operator==(const vec_T& l__a, const vec_T& l__b);  \
     
    155159#define NTL_vector_impl(T,vec_T) NTL_vector_default(T) NTL_vector_impl_plain(T,vec_T) 
    156160
     161
     162#if (!defined(NTL_CLEAN_PTR))
     163
     164#define NTL_vector_impl_position(T,vec_T) \
     165long vec_T::position(const T& l__a) const  \
     166{  \
     167   if (!_vec__rep) return -1;  \
     168   long l__num_alloc = NTL_VEC_HEAD(_vec__rep)->alloc;  \
     169   long l__num_init = NTL_VEC_HEAD(_vec__rep)->init;  \
     170   if (&l__a < _vec__rep || &l__a >= _vec__rep + l__num_alloc) return -1;  \
     171   long l__res = (&l__a) - _vec__rep;  \
     172   \
     173   if (l__res < 0 || l__res >= l__num_alloc ||   \
     174       _vec__rep + l__res != &l__a) return -1;  \
     175   \
     176   if (l__res >= l__num_init)  \
     177       NTL_NNS Error("position: reference to uninitialized object"); \
     178   return l__res;  \
     179}  \
     180  \
     181long vec_T::position1(const T& l__a) const  \
     182{  \
     183   if (!_vec__rep) return -1;  \
     184   long l__len = NTL_VEC_HEAD(_vec__rep)->length;  \
     185   if (&l__a < _vec__rep || &l__a >= _vec__rep + l__len) return -1;  \
     186   long l__res = (&l__a) - _vec__rep;  \
     187   \
     188   if (l__res < 0 || l__res >= l__len ||   \
     189       _vec__rep + l__res != &l__a) return -1;  \
     190   \
     191   return l__res;  \
     192}  \
     193
     194
     195#else
     196
     197#define NTL_vector_impl_position(T,vec_T) \
     198long vec_T::position(const T& l__a) const  \
     199{  \
     200   if (!_vec__rep) return -1;  \
     201   long l__num_alloc = NTL_VEC_HEAD(_vec__rep)->alloc;  \
     202   long l__num_init = NTL_VEC_HEAD(_vec__rep)->init;  \
     203   long l__res;  \
     204   l__res = 0;  \
     205   while (l__res < l__num_alloc && _vec__rep + l__res != &l__a)  l__res++;  \
     206   if (l__res >= l__num_alloc) return -1;  \
     207   if (l__res >= l__num_init)  \
     208       NTL_NNS Error("position: reference to uninitialized object"); \
     209   return l__res;  \
     210}  \
     211 \
     212long vec_T::position1(const T& l__a) const  \
     213{  \
     214   if (!_vec__rep) return -1;  \
     215   long l__len = NTL_VEC_HEAD(_vec__rep)->length;  \
     216   long l__res;  \
     217   l__res = 0;  \
     218   while (l__res < l__len && _vec__rep + l__res != &l__a)  l__res++;  \
     219   if (l__res >= l__len) return -1;  \
     220   return l__res;  \
     221}  \
     222
     223
     224#endif
     225
    157226#define NTL_vector_impl_plain(T,vec_T)  \
    158227 \
     
    164233      NTL_NNS Error("negative length in vector::SetLength");  \
    165234   }  \
    166    if (l__n >= long((1L << (NTL_BITS_PER_LONG-4))/sizeof(T)))  \
     235   if (NTL_OVERFLOW(l__n, sizeof(T), 0))  \
    167236      NTL_NNS Error("excessive length in vector::SetLength"); \
    168237      \
     
    180249   if (!_vec__rep) {  \
    181250      l__m = ((l__n+NTL_VectorMinAlloc-1)/NTL_VectorMinAlloc) * NTL_VectorMinAlloc; \
    182       if (l__m >= long((1L << (NTL_BITS_PER_LONG-4))/sizeof(T)))  \
    183          NTL_NNS Error("excessive length in vector::SetLength"); \
    184       char *l__p = (char *) NTL_SNS malloc(sizeof(_ntl_AlignedVectorHeader)+sizeof(T)*l__m); \
     251      char *l__p = (char *) NTL_SNS_MALLOC(l__m, sizeof(T), sizeof(_ntl_AlignedVectorHeader)); \
    185252      if (!l__p) {  \
    186253         NTL_NNS Error("out of memory in vector::SetLength()");  \
     
    202269         l__m = NTL_NNS max(l__n, long(NTL_VectorExpansionRatio*NTL_VEC_HEAD(_vec__rep)->alloc));  \
    203270         l__m = ((l__m+NTL_VectorMinAlloc-1)/NTL_VectorMinAlloc) * NTL_VectorMinAlloc; \
    204          if (l__m >= long((1L << (NTL_BITS_PER_LONG-4))/sizeof(T)))  \
    205             NTL_NNS Error("excessive length in vector::SetLength"); \
    206271         char *l__p = ((char *) _vec__rep) - sizeof(_ntl_AlignedVectorHeader); \
    207          l__p = (char *) NTL_SNS realloc(l__p, sizeof(_ntl_AlignedVectorHeader)+sizeof(T)*l__m); \
     272         l__p = (char *) NTL_SNS_REALLOC(l__p, l__m, sizeof(T), sizeof(_ntl_AlignedVectorHeader)); \
    208273         if (!l__p) {  \
    209274            NTL_NNS Error("out of memory in vector::SetLength()");  \
     
    233298      SetLength(l__n); \
    234299   else { \
    235       char *l__p = (char *) NTL_SNS malloc(sizeof(_ntl_AlignedVectorHeader)); \
     300      char *l__p = (char *) NTL_SNS_MALLOC(0, sizeof(T), sizeof(_ntl_AlignedVectorHeader)); \
    236301      if (!l__p) {  \
    237302         NTL_NNS Error("out of memory in vector::FixLength()");  \
     
    281346void vec_T::RangeError(long l__i) const  \
    282347{  \
    283    NTL_SNS Error( "index out of range in vector: ");  \
     348   printf( "index out of range in vector: %d", l__i );  \
     349   if (!_vec__rep)  \
     350      printf( "(0)\n");  \
     351   else  \
     352      printf( "(%d)\n" ,NTL_VEC_HEAD(_vec__rep)->length );  \
    284353   abort();  \
    285354}  \
    286355  \
    287 long vec_T::position(const T& l__a) const  \
    288 {  \
    289    if (!_vec__rep) return -1;  \
    290    long l__num_alloc = NTL_VEC_HEAD(_vec__rep)->alloc;  \
    291    long l__num_init = NTL_VEC_HEAD(_vec__rep)->init;  \
    292    if (&l__a < _vec__rep || &l__a >= _vec__rep + l__num_alloc) return -1;  \
    293    long l__res = (&l__a) - _vec__rep;  \
    294    \
    295    /* the next test ensures that we conform to the C/C++ standard,  \
    296       which only guarantees that relational operators are meaningful when  \
    297       pointers point to objects in the same array...I don't know  \
    298       if it ever *really* makes a diiference...  */  \
    299    \
    300    if (l__res < 0 || l__res >= l__num_alloc ||   \
    301        _vec__rep + l__res != &l__a) return -1;  \
    302    \
    303    if (l__res >= l__num_init)  \
    304        NTL_NNS Error("position: reference to uninitialized object"); \
    305    return l__res;  \
    306 }  \
     356   NTL_vector_impl_position(T,vec_T) \
    307357 \
    308358void swap(vec_T& l__x, vec_T& l__y)  \
     
    322372{  \
    323373   long l__l = l__v.length(); \
    324    long l__pos = l__v.position(l__a);  \
    325    l__v.SetLength(l__l+1);  \
    326    if (l__pos != -1)  \
    327       l__v[l__l] = l__v.RawGet(l__pos);  \
    328    else  \
     374   if (l__l >= l__v.allocated()) {  \
     375      long l__pos = l__v.position(l__a);  \
     376      l__v.SetLength(l__l+1);  \
     377      if (l__pos != -1)  \
     378         l__v[l__l] = l__v.RawGet(l__pos);  \
     379      else  \
     380         l__v[l__l] = l__a;  \
     381   } \
     382   else { \
     383      l__v.SetLength(l__l+1);  \
    329384      l__v[l__l] = l__a;  \
     385   } \
    330386}  \
    331387  \
     
    339395      l__v[l__l+l__i] = l__w[l__i];  \
    340396}
     397
    341398
    342399
  • ntl/include/NTL/version.h

    rbe2bb3 r09da99  
    33#define NTL_version__H
    44
    5 #define NTL_VERSION "5.2"
     5#define NTL_VERSION "5.3.1"
    66
    77#define NTL_MAJOR_VERSION  (5)
    8 #define NTL_MINOR_VERSION  (2)
    9 #define NTL_REVISION       (0)
     8#define NTL_MINOR_VERSION  (3)
     9#define NTL_REVISION       (1)
    1010
    1111#endif
  • ntl/include/NTL/xdouble.h

    rbe2bb3 r09da99  
    217217inline void conv(xdouble& x, double a) { x = to_xdouble(a); }
    218218inline void conv(xdouble& x, const char *a) { x = to_xdouble(a); }
     219
    219220xdouble trunc(const xdouble& a);
    220221xdouble floor(const xdouble& a);
Note: See TracChangeset for help on using the changeset viewer.