gmp_lib.mpz_init2 Method

GMP Native Interface for .NET

gmp_libmpz_init2 Method
Initialize x, with space for n-bit numbers, and set its value to 0.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void mpz_init2(
	mpz_t x,
	mp_bitcnt_t n
)
Public Shared Sub mpz_init2 ( 
	x As mpz_t,
	n As mp_bitcnt_t
)
public:
static void mpz_init2(
	mpz_t^ x, 
	mp_bitcnt_t n
)
static member mpz_init2 : 
        x : mpz_t * 
        n : mp_bitcnt_t -> unit 

Parameters

x
Type: Math.Gmp.Nativempz_t
The integer.
n
Type: Math.Gmp.Nativemp_bitcnt_t
The number of bits.
Remarks

Calling this function instead of mpz_init or mpz_inits is never necessary; reallocation is handled automatically by GMP when needed.

While n defines the initial space, x will grow automatically in the normal way, if necessary, for subsequent values stored. mpz_init2 makes it possible to avoid such reallocations if a maximum size is known in advance.

In preparation for an operation, GMP often allocates one limb more than ultimately needed. To make sure GMP will not perform reallocation for x, you need to add the number of bits in mp_limb_t to n.

Examples
// Create a new integer x, and initialize its size to 300 bits.
mpz_t x = new mpz_t();
gmp_lib.mpz_init2(x, 300);

// Assert that the value of x is 0.
Assert.IsTrue(gmp_lib.mpz_get_si(x) == 0);

// Release unmanaged memory allocated for x.
gmp_lib.mpz_clear(x);
' Create a new integer x, and initialize its size to 300 bits.
Dim x As New mpz_t()
gmp_lib.mpz_init2(x, 300)

' Assert that the value of x is 0.
Assert.IsTrue(gmp_lib.mpz_get_si(x) = 0)

' Release unmanaged memory allocated for x.
gmp_lib.mpz_clear(x)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also