Click or drag to resize
gmp_libmpz_getlimbn Method
Return limb number n from op.

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_limb_t mpz_getlimbn(
	mpz_t op,
	mp_size_t n
)

Parameters

op
Type: Math.Gmp.Nativempz_t
The operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The zero-based limb index.

Return Value

Type: mp_limb_t
The limb number n from op.
Remarks

The sign of op is ignored, just the absolute value is used. The least significant limb is number 0.

mpz_size can be used to find how many limbs make up op. mpz_getlimbn returns zero if n is outside the range 0 to mpz_size(op) - 1.

Examples
// Create and initialize new integer x.
mpz_t op = new mpz_t();
char_ptr value = new char_ptr("1000 ABCD 1234 7AB8 24FD");
gmp_lib.mpz_init_set_str(op, value, 16);

// Assert the value of the limbs of op.
if (gmp_lib.mp_bytes_per_limb == 4)
{
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 0) == 0x7AB824FD);
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 1) == 0xABCD1234);
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 2) == 0x00001000);
}
else // gmp_lib.mp_bytes_per_limb == 8
{
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 0) == 0xABCD12347AB824FD);
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 1) == 0x0000000000001000);
}

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