gmp_lib.mpz_tdiv_qr Method

GMP Native Interface for .NET

gmp_libmpz_tdiv_qr Method
Set the quotient q to trunc(n / d), and set the remainder r to n - q * d.

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 mpz_tdiv_qr(
	mpz_t q,
	mpz_t r,
	mpz_t n,
	mpz_t d
)
Public Shared Sub mpz_tdiv_qr ( 
	q As mpz_t,
	r As mpz_t,
	n As mpz_t,
	d As mpz_t
)
public:
static void mpz_tdiv_qr(
	mpz_t^ q, 
	mpz_t^ r, 
	mpz_t^ n, 
	mpz_t^ d
)
static member mpz_tdiv_qr : 
        q : mpz_t * 
        r : mpz_t * 
        n : mpz_t * 
        d : mpz_t -> unit 

Parameters

q
Type: Math.Gmp.Nativempz_t
The result quotient integer.
r
Type: Math.Gmp.Nativempz_t
The result remainder integer.
n
Type: Math.Gmp.Nativempz_t
The numerator integer.
d
Type: Math.Gmp.Nativempz_t
The denominator integer.
Examples
// Create, initialize, and set the value of n to 10000.
mpz_t n = new mpz_t();
gmp_lib.mpz_init_set_si(n, 10000);

// Create, initialize, and set the value of d to 3.
mpz_t d = new mpz_t();
gmp_lib.mpz_init_set_si(d, 3);

// Create, initialize, and set the values of q and r to 0.
mpz_t q = new mpz_t();
mpz_t r = new mpz_t();
gmp_lib.mpz_inits(q, r, null);

// Set q = trunc(n / 3) and r = n - d * q.
gmp_lib.mpz_tdiv_qr(q, r, n, d);

// Assert that q is 3333, and that r is 1.
Assert.IsTrue(gmp_lib.mpz_get_si(q) == 3333);
Assert.IsTrue(gmp_lib.mpz_get_si(r) == 1);

// Release unmanaged memory allocated for n, d, q, and r.
gmp_lib.mpz_clears(n, d, q, r, null);
' Create, initialize, and set the value of n to 10000.
Dim n As New mpz_t()
gmp_lib.mpz_init_set_si(n, 10000)

' Create, initialize, and set the value of d to 3.
Dim d As New mpz_t()
gmp_lib.mpz_init_set_si(d, 3)

' Create, initialize, and set the values of q and r to 0.
Dim q As New mpz_t()
Dim r As New mpz_t()
gmp_lib.mpz_inits(q, r, Nothing)

' Set q = trunc(n / 3) and r = n - d * q.
gmp_lib.mpz_tdiv_qr(q, r, n, d)

' Assert that q is 3333, and that r is 1.
Assert.IsTrue(gmp_lib.mpz_get_si(q) = 3333)
Assert.IsTrue(gmp_lib.mpz_get_si(r) = 1)

' Release unmanaged memory allocated for n, d, q, and r.
gmp_lib.mpz_clears(n, d, q, r, Nothing)

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