gmp_lib.mpn_sec_div_qr Method

GMP Native Interface for .NET

gmp_libmpn_sec_div_qr Method
Set Q to the truncated quotient N / D and R to N modulo D, where N = {np, nn}, D = {dp, dn}, Q’s most significant limb is the function return value and the remaining limbs are {qp, nn - dn}, and R = {np, dn}.

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 mpn_sec_div_qr(
	mp_ptr qp,
	mp_ptr np,
	mp_size_t nn,
	mp_ptr dp,
	mp_size_t dn,
	mp_ptr tp
)
Public Shared Function mpn_sec_div_qr ( 
	qp As mp_ptr,
	np As mp_ptr,
	nn As mp_size_t,
	dp As mp_ptr,
	dn As mp_size_t,
	tp As mp_ptr
) As mp_limb_t
public:
static mp_limb_t mpn_sec_div_qr(
	mp_ptr^ qp, 
	mp_ptr^ np, 
	mp_size_t nn, 
	mp_ptr^ dp, 
	mp_size_t dn, 
	mp_ptr^ tp
)
static member mpn_sec_div_qr : 
        qp : mp_ptr * 
        np : mp_ptr * 
        nn : mp_size_t * 
        dp : mp_ptr * 
        dn : mp_size_t * 
        tp : mp_ptr -> mp_limb_t 

Parameters

qp
Type: Math.Gmp.Nativemp_ptr
The quotient result operand.
np
Type: Math.Gmp.Nativemp_ptr
The first operand and remainder result integer.
nn
Type: Math.Gmp.Nativemp_size_t
The number of limbs of np.
dp
Type: Math.Gmp.Nativemp_ptr
The second operand integer.
dn
Type: Math.Gmp.Nativemp_size_t
The number of limbs of dp.
tp
Type: Math.Gmp.Nativemp_ptr
The scratch operand integer.

Return Value

Type: mp_limb_t
Q’s most significant limb.
Remarks

It is required that nndn ≥ 1, and that dp[dn - 1] ≠ 0. This does not imply that N ≥ D since N might be zero-padded.

Note the overlapping between N and R. No other operand overlapping is allowed. The entire space occupied by N is overwritten.

This function requires scratch space of mpn_sec_div_qr_itch(nn, dn) limbs to be passed in the tp parameter.

Examples
// Create multi-precision operands, and expected result.
mp_ptr np = new mp_ptr(new uint[] { 0xffffffff, 0x0000ffff });
mp_ptr dp = new mp_ptr(new uint[] { 0x00000003 });
mp_ptr remainder = new mp_ptr(new uint[] { 0x00000000 });
mp_ptr qp = new mp_ptr(new uint[np.Size]);

// Create scratch space.
mp_size_t size = gmp_lib.mpn_sec_div_qr_itch(np.Size, dp.Size);
mp_ptr tp = new mp_ptr(size);

// Set qp = floor(np / dp) and rp = np mod dp.
mp_limb_t mslimb = gmp_lib.mpn_sec_div_qr(qp, np, np.Size, dp, dp.Size, tp);

// Assert result of operation.
Assert.IsTrue(mslimb == (ulong)(gmp_lib.mp_bytes_per_limb == 4 ? 0x00005555 : 0x0000555555555555));
Assert.IsTrue(qp[0] == (ulong)(gmp_lib.mp_bytes_per_limb == 4 ? 0x55555555 : 0x0000000000000000));
Assert.IsTrue(np[0] == remainder[0]);

// Release unmanaged memory.
gmp_lib.free(qp, np, dp, remainder, tp);
' Create multi-precision operands, and expected result.
Dim np As New mp_ptr(New UInteger() { &HffffffffUI, &Hffff})
Dim dp As New mp_ptr(New UInteger() { &H3})
Dim remainder As New mp_ptr(New UInteger() { &H0})
Dim qp As New mp_ptr(New UInteger(np.Size - 1) { })

' Create scratch space.
Dim size As mp_size_t = gmp_lib.mpn_sec_div_qr_itch(np.Size, dp.Size)
Dim tp As New mp_ptr(size)

' Set qp = floor(np / dp) and rp = np mod dp.
Dim mslimb As mp_limb_t = gmp_lib.mpn_sec_div_qr(qp, np, np.Size, dp, dp.Size, tp)

' Assert result of operation.
Assert.IsTrue(mslimb = CULng(If(gmp_lib.mp_bytes_per_limb = 4, &H5555, &H555555555555L)))
Assert.IsTrue(qp(0) = CULng(If(gmp_lib.mp_bytes_per_limb = 4, &H55555555, &H0)))
Assert.IsTrue(np(0) = remainder(0))

' Release unmanaged memory.
gmp_lib.free(qp, np, dp, remainder, tp)

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