Click or drag to resize
gmp_libmpn_gcd Method
Set {rp, retval} to the greatest common divisor of {xp, xn} and {yp, yn}.

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_size_t mpn_gcd(
	mp_ptr rp,
	mp_ptr xp,
	mp_size_t xn,
	mp_ptr yp,
	mp_size_t yn
)

Parameters

rp
Type: Math.Gmp.Nativemp_ptr
The result integer.
xp
Type: Math.Gmp.Nativemp_ptr
The first operand integer.
xn
Type: Math.Gmp.Nativemp_size_t
The number of limbs of xp.
yp
Type: Math.Gmp.Nativemp_ptr
The second operand integer.
yn
Type: Math.Gmp.Nativemp_size_t
The number of limbs of yp.

Return Value

Type: mp_size_t
The result can be up to yn limbs, the return value is the actual number produced; i.e. the number of limbs of rp.
Remarks

Both source operands are destroyed.

It is required that xnyn > 0, and the most significant limb of {yp, yn} must be non-zero. No overlap is permitted between {xp, xn} and {yp, yn}.

Examples
// Create multi-precision operands, and expected result.
mp_ptr xp = new mp_ptr(new uint[] { 0x964619c7, 0x00000002 });
mp_ptr yp = new mp_ptr(new uint[] { 0xc2d24d55, 0x00000007 });
mp_ptr rp = new mp_ptr(yp.Size);
mp_ptr result = new mp_ptr(new uint[] { 0x964619c7, 0x00000002 });

// Set rp = gcd(xp, yp).
mp_size_t size = gmp_lib.mpn_gcd(rp, xp, xp.Size, yp, yp.Size);

// Assert result of operation.
Assert.IsTrue(size == result.Size);
Assert.IsTrue(rp.SequenceEqual(result));

// Release unmanaged memory.
gmp_lib.free(rp, xp, yp, result);
See Also