GNU Multiple Precision(GMP)库笔记

                     

贡献者: addis

  • 本文处于草稿阶段。

   GMP 可能是最常用的大整数库。Boost 的 Multiprecision 库也提供 C++ 的 wrapper(可以选择后台用 GMP 或者其他库),封装得更为友好。

1. 数据结构

#ifdef _LONG_LONG_LIMB
typedef unsigned long long int	mp_limb_t;
typedef long long int		mp_limb_signed_t;
#else
typedef unsigned long int	mp_limb_t;
typedef long int		mp_limb_signed_t;
#endif

typedef mp_limb_t *mp_ptr;
typedef const mp_limb_t *mp_srcptr;

/* For reference, note that the name __mpz_struct gets into C++ mangled
   function names, which means although the "__" suggests an internal, we
   must leave this name for binary compatibility.  */
typedef struct
{
  int _mp_alloc;		/* Number of *limbs* allocated and pointed
				   to by the _mp_d field.  */
  int _mp_size;			/* abs(_mp_size) is the number of limbs the
				   last field points to.  If _mp_size is
				   negative this is a negative number.  */
  mp_limb_t *_mp_d;		/* Pointer to the limbs.  */
} __mpz_struct;

typedef __mpz_struct MP_INT;    /* gmp 1 source compatibility */
typedef __mpz_struct mpz_t[1];

                     

© 小时科技 保留一切权利