gmp_lib.mpn_tdiv_qr Method

GMP Native Interface for .NET

gmp_libmpn_tdiv_qr Method
Divide {np, nn} by {dp, dn} and put the quotient at {qp, nn - dn + 1} and the remainder at {rp, 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 void mpn_tdiv_qr(
	mp_ptr qp,
	mp_ptr rp,
	mp_size_t qxn,
	mp_ptr np,
	mp_size_t nn,
	mp_ptr dp,
	mp_size_t dn
)
Public Shared Sub mpn_tdiv_qr ( 
	qp As mp_ptr,
	rp As mp_ptr,
	qxn As mp_size_t,
	np As mp_ptr,
	nn As mp_size_t,
	dp As mp_ptr,
	dn As mp_size_t
)
public:
static void mpn_tdiv_qr(
	mp_ptr^ qp, 
	mp_ptr^ rp, 
	mp_size_t qxn, 
	mp_ptr^ np, 
	mp_size_t nn, 
	mp_ptr^ dp, 
	mp_size_t dn
)
static member mpn_tdiv_qr : 
        qp : mp_ptr * 
        rp : mp_ptr * 
        qxn : mp_size_t * 
        np : mp_ptr * 
        nn : mp_size_t * 
        dp : mp_ptr * 
        dn : mp_size_t -> unit 

Parameters

qp
Type: Math.Gmp.Nativemp_ptr
The result quotient integer.
rp
Type: Math.Gmp.Nativemp_ptr
The result remainder integer.
qxn
Type: Math.Gmp.Nativemp_size_t
Must be 0.
np
Type: Math.Gmp.Nativemp_ptr
The numerator operand integer.
nn
Type: Math.Gmp.Nativemp_size_t
The number of limbs of np.
dp
Type: Math.Gmp.Nativemp_ptr
The denominator operand integer.
dn
Type: Math.Gmp.Nativemp_size_t
The number of limbs of dp.
Remarks

The quotient is rounded towards 0.

No overlap is permitted between arguments, except that np might equal rp. The dividend size nn must be greater than or equal to divisor size dn. The most significant limb of the divisor must be non-zero. The qxn operand must be zero.

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[] { 0x00000013 });
mp_ptr qp = new mp_ptr(new uint[np.Size - dp.Size + 1]);
mp_ptr rp = new mp_ptr(new uint[dp.Size]);
mp_ptr quotient = new mp_ptr(new uint[] { 0x435e50d7, 0x00000d79 });
mp_ptr remainder = new mp_ptr(new uint[] { 0x0000000a });

// Set rp = np / dp.
gmp_lib.mpn_tdiv_qr(qp, rp, 0, np, np.Size, dp, dp.Size);

// Assert result of operation.
Assert.IsTrue(qp.SequenceEqual(quotient));
Assert.IsTrue(rp.SequenceEqual(remainder));

// Release unmanaged memory.
gmp_lib.free(qp, rp, np, dp, quotient, remainder);
' 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() { &H13})
Dim qp As New mp_ptr(New UInteger(np.Size - dp.Size) { })
Dim rp As New mp_ptr(New UInteger(dp.Size - 1) { })
Dim quotient As New mp_ptr(New UInteger() { &H435e50d7, &Hd79})
Dim remainder As New mp_ptr(New UInteger() { &Ha})

' Set rp = np / dp.
gmp_lib.mpn_tdiv_qr(qp, rp, 0, np, np.Size, dp, dp.Size)

' Assert result of operation.
Assert.IsTrue(qp.SequenceEqual(quotient))
Assert.IsTrue(rp.SequenceEqual(remainder))

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

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