gmp_lib.mpz_limbs_modify Method

GMP Native Interface for .NET

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
)
Public Shared Function mpz_limbs_modify ( 
	x As mpz_t,
	n As mp_size_t
) As mp_ptr
public:
static mp_ptr^ mpz_limbs_modify(
	mpz_t^ x, 
	mp_size_t n
)
static member mpz_limbs_modify : 
        x : mpz_t * 
        n : mp_size_t -> mp_ptr 

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);
' Create, initialize, and set the value of x to 2.
Dim x As New mpz_t()
gmp_lib.mpz_init_set_ui(x, 2UI)

' Resize x to 3 limbs, and get pointer to the limbs.
Dim limbs As mp_ptr = gmp_lib.mpz_limbs_modify(x, 3)

' Set the value of x.
limbs(0) = 0
limbs(1) = 0
limbs(2) = (If(IntPtr.Size = 4, 8UI, 64UI))
gmp_lib.mpz_limbs_finish(x, -3)

' Assert the value of x based on current architecture (x86 or x64).
Dim s As char_ptr = gmp_lib.mpz_get_str(char_ptr.Zero, If(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)

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