gmp_lib._mpz_realloc Method

GMP Native Interface for .NET

gmp_lib_mpz_realloc Method
Change the space for integer to new_alloc limbs.

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_realloc(
	mpz_t integer,
	mp_size_t new_alloc
)
Public Shared Sub _mpz_realloc ( 
	integer As mpz_t,
	new_alloc As mp_size_t
)
public:
static void _mpz_realloc(
	mpz_t^ integer, 
	mp_size_t new_alloc
)
static member _mpz_realloc : 
        integer : mpz_t * 
        new_alloc : mp_size_t -> unit 

Parameters

integer
Type: Math.Gmp.Nativempz_t
The integer to resize.
new_alloc
Type: Math.Gmp.Nativemp_size_t
The new number of limbs.
Remarks

The value in integer is preserved if it fits, or is set to 0 if not.

mpz_realloc2 is the preferred way to accomplish allocation changes like this. mpz_realloc2 and _mpz_realloc are the same except that _mpz_realloc takes its size in limbs.

Examples
// Create and initialize new integer x.
mpz_t x = new mpz_t();
gmp_lib.mpz_init(x);

// Set the value of x to a 77-bit integer.
char_ptr value = new char_ptr("1000 0000 0000 0000 0000");
gmp_lib.mpz_set_str(x, value, 16);

// Resize x to 50 limbs, and assert that its value has not changed.
gmp_lib._mpz_realloc(x, 50);
char_ptr s = gmp_lib.mpz_get_str(char_ptr.Zero, 16, x);
Assert.IsTrue(s.ToString() == "1000 0000 0000 0000 0000".Replace(" ", ""));

// Resize x to 1 limb, and assert that its value has changed to 0.
gmp_lib._mpz_realloc(x, 1);
Assert.IsTrue(gmp_lib.mpz_get_si(x) == 0);

// Release unmanaged memory allocated for x and string values.
gmp_lib.mpz_clear(x);
gmp_lib.free(value);
gmp_lib.free(s);
' Create and initialize new integer x.
Dim x As New mpz_t()
gmp_lib.mpz_init(x)

' Set the value of x to a 77-bit integer.
Dim value As New char_ptr("1000 0000 0000 0000 0000")
gmp_lib.mpz_set_str(x, value, 16)

' Resize x to 50 limbs, and assert that its value has not changed.
gmp_lib._mpz_realloc(x, 50)
Dim s As char_ptr = gmp_lib.mpz_get_str(char_ptr.Zero, 16, x)
Assert.IsTrue(s.ToString() = "1000 0000 0000 0000 0000".Replace(" ", ""))

' Resize x to 1 limb, and assert that its value has changed to 0.
gmp_lib._mpz_realloc(x, 1)
Assert.IsTrue(gmp_lib.mpz_get_si(x) = 0)

' Release unmanaged memory allocated for x and string values.
gmp_lib.mpz_clear(x)
gmp_lib.free(value)
gmp_lib.free(s)

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