gmp_lib.mpz_roinit_n Method

GMP Native Interface for .NET

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

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);
' Create and initialize new integer x.
Dim x As New mpz_t()
gmp_lib.mpz_init(x)

' Prepare new limbs for x.
Dim limbs As mp_ptr
If gmp_lib.mp_bytes_per_limb = 4 Then
    limbs = New mp_ptr(New UInteger() { 0UI, 0UI, 2UI})
Else
    limbs = New mp_ptr(New ULong() { 0UL, 0UL, 4UL})
End If

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

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

See Also