gmp_lib.mpz_getlimbn Method

GMP Native Interface for .NET

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

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);
' Create and initialize new integer x.
Dim op As New mpz_t()
Dim value As 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 Then
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 0) = &H7ab824fd)
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 1) = &Habcd1234UI)
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 2) = &H1000)
Else ' gmp_lib.mp_bytes_per_limb == 8
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 0) = &Habcd12347ab824fdUL)
    Assert.IsTrue(gmp_lib.mpz_getlimbn(op, 1) = &H1000)
End If

' Release unmanaged memory allocated for op and value.
gmp_lib.mpz_clear(op)
gmp_lib.free(value)

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