Click or drag to resize
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
)

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);
See Also