using System; using System.Diagnostics; namespace Math.Gmp.Native { /// /// Provides common functionality to mpz_t, mpf_t, and gmp_randstate_t. /// public class mp_base { /// /// Pointer to limbs in unmanaged memory. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")] [DebuggerBrowsable(DebuggerBrowsableState.Never)] public IntPtr Pointer; [DebuggerBrowsable(DebuggerBrowsableState.Never)] internal mp_size_t _size; /// /// The number of limbs. /// /// public virtual mp_size_t _mp_size { get { return _size; } } /// /// Gets or sets the pointer to limbs in unmanaged memory. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] public virtual IntPtr _mp_d_intptr { get { return Pointer; } set { Pointer = value; } } [DebuggerBrowsable(DebuggerBrowsableState.Never)] private mp_ptr __mp_d = null; /// /// A pointer to an array of limbs which is the magnitude. /// /// /// /// In mpz_t: /// /// /// A pointer to an array of limbs which is the magnitude. /// These are stored “little endian” as per the mpn functions, so _mp_d[0] /// is the least significant limb and _mp_d[ABS(_mp_size) - 1] /// is the most significant. /// Whenever _mp_size is non-zero, the most significant limb is non-zero. /// /// /// Currently there’s always at least one limb allocated, so for instance gmp_lib.mpz_set_ui /// never needs to reallocate, and gmp_lib.mpz_get_ui can fetch _mp_d[0] /// unconditionally (though its value is then only wanted if _mp_size is non-zero). /// /// /// In mpz_t: /// /// /// A pointer to the array of limbs which is the absolute value of the mantissa. /// These are stored "little endian" as per the mpn functions, so _mp_d[0] is the least /// significant limb and _mp_d[ABS(_mp_size)-1] the most significant. /// /// /// The most significant limb is always non-zero, but there are no other restrictions on its value, /// in particular the highest 1 bit can be anywhere within the limb. /// /// /// _mp_prec + 1 limbs are allocated to mp_base._mp_d, the extra limb being for /// convenience (see below). /// There are no reallocations during a calculation, only in a change of precision with gmp_lib.mpf_set_prec. /// /// public virtual mp_ptr _mp_d { get { if (__mp_d == null) __mp_d = new mp_ptr(this); return __mp_d; } } } }