Click or drag to resize
gmp_libmpz_roinit_n Method
Special initialization of x, using the given limb array and size.

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 mpz_t mpz_roinit_n(
	mpz_t x,
	mp_ptr xp,
	mp_size_t xs
)

Parameters

x
Type: Math.Gmp.Nativempz_t
The operand integer.
xp
Type: Math.Gmp.Nativemp_ptr
The limbs array.
xs
Type: Math.Gmp.Nativemp_size_t
The number of limbs and the sign.

Return Value

Type: mpz_t
For convenience, the function returns x, but cast to a const pointer type.
Remarks

x should be treated as readonly: it can be passed safely as input to any mpz function, but not as an output. The array xp must point to at least a readable limb, its size is | xs |, and the sign of x is the sign of xs.

C++
void foo (mpz_t x)
{
    static const mp_limb_t y[3] = { 0x1, 0x2, 0x3 };
    mpz_t tmp;
    mpz_add(x, x, mpz_roinit_n(tmp, y, 3));
}
Examples
// Create and initialize new integer x.
mpz_t x = new mpz_t();
gmp_lib.mpz_init(x);

// Prepare new limbs for x.
mp_ptr limbs;
if (gmp_lib.mp_bytes_per_limb == 4)
    limbs = new mp_ptr(new uint[] { 0U, 0U, 2U });
else
    limbs = new mp_ptr(new ulong[] { 0UL, 0UL, 4UL });

// Assign new limbs to x, and make x negative.
x = gmp_lib.mpz_roinit_n(x, limbs, -3);

// Assert new value of x.
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