GMP Native Interface for .NET
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)

public static mp_ptr mpz_limbs_write( mpz_t x, mp_size_t n )
Public Shared Function mpz_limbs_write ( x As mpz_t, n As mp_size_t ) As mp_ptr
public: static mp_ptr^ mpz_limbs_write( mpz_t^ x, mp_size_t n )
static member mpz_limbs_write : 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_ptrA pointer to the limb array of x, intended for write access.

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.

// 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);
' Create and initialize new integer x. Dim x As 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, 2UI) Dim limbs As mp_ptr = gmp_lib.mpz_limbs_write(x, 3) ' Set the values of the limbs. limbs(0) = 0UI limbs(1) = 0UI limbs(2) = (If(gmp_lib.mp_bytes_per_limb = 4, 2UI, 4UI)) 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() = "-10 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.
