Click or drag to resize
gmp_libmpz_limbs_write 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_write(
	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_write function may destroy the old value and return an array with unspecified contents.

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

// Resize x to 3 limbs, and get pointer to the limbs.
gmp_lib.mpz_set_ui(x, 2U);
mp_ptr limbs = gmp_lib.mpz_limbs_write(x, 3);

// Set the values of the limbs.
limbs[0] = 0U;
limbs[1] = 0U;
limbs[2] = (gmp_lib.mp_bytes_per_limb == 4 ? 2U : 4U);
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() == "-10 00000000000000000000000000000000 00000000000000000000000000000000".Replace(" ", ""));

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