⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 g_lip.h

📁 密码大家Shoup写的数论算法c语言实现
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifdef NTL_SINGLE_MUL#error "do not set NTL_SINGLE_MUL when NTL_GMP_LIP is set"#endif#if 1typedef void *_ntl_gbigint;#else/* * This way of defining the bigint handle type is a bit non-standard, * but better for debugging. */struct _ntl_gbigint_is_opaque { int _x_; };typedef struct _ntl_gbigint_is_opaque * _ntl_gbigint;#endif#define NTL_SP_NBITS NTL_NBITS_MAX#define NTL_SP_BOUND (1L << NTL_SP_NBITS)#define NTL_SP_FBOUND ((double) NTL_SP_BOUND)#define NTL_WSP_NBITS (NTL_BITS_PER_LONG-2)#define NTL_WSP_BOUND (1L << NTL_WSP_NBITS)/* define the following so an error is raised */#define NTL_RADIX ......#define NTL_NBITSH ......#define NTL_RADIXM ......#define NTL_RADIXROOT ......#define NTL_RADIXROOTM ......#define NTL_FRADIX_INV ......#if (defined(__cplusplus) && !defined(NTL_CXX_ONLY))extern "C" {#endif/***********************************************************************   Basic Functions***********************************************************************/        void _ntl_gsadd(_ntl_gbigint a, long d, _ntl_gbigint *b);       /* *b = a + d */    void _ntl_gadd(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *c);       /*  *c = a + b */    void _ntl_gsub(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *c);       /* *c = a - b */    void _ntl_gsubpos(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *c);       /* *c = a - b; assumes a >= b >= 0 */    void _ntl_gsmul(_ntl_gbigint a, long d, _ntl_gbigint *b);       /* *b = d * a */    void _ntl_gmul(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *c);       /* *c = a * b */    void _ntl_gsq(_ntl_gbigint a, _ntl_gbigint *c);       /* *c = a * a */    long _ntl_gsdiv(_ntl_gbigint a, long b, _ntl_gbigint *q);       /* (*q) = floor(a/b) and a - floor(a/b)*(*q) is returned;          error is raised if b == 0;          if b does not divide a, then sign(*q) == sign(b) */    void _ntl_gdiv(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *q, _ntl_gbigint *r);       /* (*q) = floor(a/b) and (*r) = a - floor(a/b)*(*q);          error is raised if b == 0;          if b does not divide a, then sign(*q) == sign(b) */    void _ntl_gmod(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *r);       /* same as _ntl_gdiv, but only remainder is computed */    long _ntl_gsmod(_ntl_gbigint a, long d);       /* same as _ntl_gsdiv, but only remainder is computed */    void _ntl_gquickmod(_ntl_gbigint *r, _ntl_gbigint b);       /* *r = *r % b; 	  The division is performed in place (but may sometimes	  assumes b > 0 and *r >= 0;          cause *r to grow by one digit) *//********************************************************************   Shifting and bit manipulation*********************************************************************/    void _ntl_glshift(_ntl_gbigint n, long k, _ntl_gbigint *a);       /* *a = sign(n) * (|n| << k);          shift is in reverse direction for negative k */    void _ntl_grshift(_ntl_gbigint n, long k, _ntl_gbigint *a);       /* *a = sign(n) * (|n| >> k);          shift is in reverse direction for negative k */        long _ntl_gmakeodd(_ntl_gbigint *n);       /*          if (n != 0)              *n = m;              return (k such that n == 2 ^ k * m with m odd);          else              return (0);         */    long _ntl_gnumtwos(_ntl_gbigint n);        /* return largest e such that 2^e divides n, or zero if n is zero */    long _ntl_godd(_ntl_gbigint a);       /* returns 1 if n is odd and 0 if it is even */    long _ntl_gbit(_ntl_gbigint a, long p);       /* returns p-th bit of a, where the low order bit is indexed by 0;          p out of range returns 0 */    long _ntl_gsetbit(_ntl_gbigint *a, long p);       /* returns original value of p-th bit of |a|, and replaces          p-th bit of a by 1 if it was zero;          error if p < 0 */    long _ntl_gswitchbit(_ntl_gbigint *a, long p);       /* returns original value of p-th bit of |a|, and switches          the value of p-th bit of a;          p starts counting at 0;          error if p < 0 */     void _ntl_glowbits(_ntl_gbigint a, long k, _ntl_gbigint *b);        /* places k low order bits of |a| in b */      long _ntl_gslowbits(_ntl_gbigint a, long k);        /* returns k low order bits of |a| */    long _ntl_gweights(long a);        /* returns Hamming weight of |a| */    long _ntl_gweight(_ntl_gbigint a);        /* returns Hamming weight of |a| */    void _ntl_gand(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *c);        /* c gets bit pattern `bits of |a|` and `bits of |b|` */    void _ntl_gor(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *c);        /* c gets bit pattern `bits of |a|` inclusive or `bits of |b|` */    void _ntl_gxor(_ntl_gbigint a, _ntl_gbigint b, _ntl_gbigint *c);        /* c gets bit pattern `bits of |a|` exclusive or `bits of |b|` *//************************************************************************   Comparison*************************************************************************/    long _ntl_gcompare(_ntl_gbigint a, _ntl_gbigint b);       /*          if (a > b)              return (1);          if (a == b)              return (0);          if (a < b)              return (-1);         */    long _ntl_gscompare(_ntl_gbigint a, long b);       /* single-precision version of the above */    long _ntl_giszero (_ntl_gbigint a);       /* test for 0 */    long _ntl_gsign(_ntl_gbigint a);       /*           if (a > 0)              return (1);          if (a == 0)              return (0);          if (a < 0)              return (-1);        */    void _ntl_gabs(_ntl_gbigint *a);       /* *a = |a| */    void _ntl_gnegate(_ntl_gbigint *a);       /* *a = -a */    void _ntl_gcopy(_ntl_gbigint a, _ntl_gbigint *b);       /* *b = a;  */    void _ntl_gswap(_ntl_gbigint *a, _ntl_gbigint *b);       /* swap a and b (by swaping pointers) */    long _ntl_g2log(_ntl_gbigint a);       /* number of bits in |a|; returns 0 if a = 0 */    long _ntl_g2logs(long a);        /* single-precision version of the above *//********************************************************************   Conversion*********************************************************************/            void _ntl_gzero(_ntl_gbigint *a);       /* *a = 0;  */    void _ntl_gone(_ntl_gbigint *a);       /* *a = 1 */    void _ntl_gintoz(long d, _ntl_gbigint *a);       /* *a = d;  */    void _ntl_guintoz(unsigned long d, _ntl_gbigint *a);       /* *a = d;  space is allocated  */    long _ntl_gtoint(_ntl_gbigint a);       /* converts a to a long;  overflow results in value          mod 2^{NTL_BITS_PER_LONG}. */    unsigned long _ntl_gtouint(_ntl_gbigint a);       /* converts a to a long;  overflow results in value          mod 2^{NTL_BITS_PER_LONG}. */       double _ntl_gdoub(_ntl_gbigint n);       /* converts a to a double;  no overflow check */    long _ntl_ground_correction(_ntl_gbigint a, long k, long residual);       /* k >= 1, |a| >= 2^k, and residual is 0, 1, or -1.          The result is what we should add to (a >> k) to round          x = a/2^k to the nearest integer using IEEE-like rounding rules          (i.e., round to nearest, and round to even to break ties).          The result is either 0 or sign(a).          If residual is not zero, it is as if x were replaced by          x' = x + residual*2^{-(k+1)}.          This can be used to break ties when x is exactly          half way between two integers. */    double _ntl_glog(_ntl_gbigint a);       /* computes log(a), protecting against overflow */    void _ntl_gdoubtoz(double a, _ntl_gbigint *x);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -