Click or drag to resize
gmp_libmpz_limbs_modify Method
Return a pointer to the limb array of x, intended for write access.

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 mp_ptr mpz_limbs_modify(
	mpz_t x,
	mp_size_t n
)

Parameters

x
Type: Math.Gmp.Nativempz_t
The operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The number of limbs.

Return Value

Type: mp_ptr
A pointer to the limb array of x, intended for write access.
Remarks

The array is reallocated as needed, to make room for n limbs. Requires n > 0. The mpz_limbs_modify function returns an array that holds the old absolute value of x

Examples
// Create, initialize, and set the value of x to 2.
mpz_t x = new mpz_t();
gmp_lib.mpz_init_set_ui(x, 2U);

// Resize x to 3 limbs, and get pointer to the limbs.
mp_ptr limbs = gmp_lib.mpz_limbs_modify(x, 3);

// Set the value of x.
limbs[0] = 0;
limbs[1] = 0;
limbs[2] = (IntPtr.Size == 4 ? 8U : 64U);
gmp_lib.mpz_limbs_finish(x, -3);

// Assert the value of x based on current architecture (x86 or x64).
char_ptr s = gmp_lib.mpz_get_str(char_ptr.Zero, gmp_lib.mp_bytes_per_limb == 4 ? 2 : 4, x);
Assert.IsTrue(s.ToString() == "-1000 00000000000000000000000000000000 00000000000000000000000000000000".Replace(" ", ""));

// Release unmanaged memory allocated for x and s.
gmp_lib.mpz_clear(x);
gmp_lib.free(s);
See Also