Click or drag to resize
gmp_libmpn_sub Method
Subtract {s2p, s2n} from {s1p, s1n}, and write the s1n least significant limbs of the result to rp.

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_sub(
	mp_ptr rp,
	mp_ptr s1p,
	mp_size_t s1n,
	mp_ptr s2p,
	mp_size_t s2n
)

Parameters

rp
Type: Math.Gmp.Nativemp_ptr
The result integer.
s1p
Type: Math.Gmp.Nativemp_ptr
The first operand integer.
s1n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of s1p.
s2p
Type: Math.Gmp.Nativemp_ptr
The second operand integer.
s2n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of s2p.

Return Value

Type: mp_limb_t
Return borrow, either 0 or 1.
Remarks

This is the lowest-level function for subtraction. It is the preferred function for subtraction, since it is written in assembly for most CPUs.

Examples
// Create multi-precision operands, and expected result.
mp_ptr s1p = new mp_ptr(new uint[] { 0xffffffff, 0xffffffff });
mp_ptr s2p = new mp_ptr(new uint[] { 0x00000001 });
mp_ptr rp = new mp_ptr(new uint[2]);
mp_ptr result = new mp_ptr(new uint[] { 0xfffffffe, 0xffffffff });

// Set rp = s1 - s2.
mp_limb_t borrow = gmp_lib.mpn_sub(rp, s1p, s1p.Size, s2p, s2p.Size);

// Assert result of operation.
Assert.IsTrue(borrow == 0);
Assert.IsTrue(rp.SequenceEqual(result));

// Release unmanaged memory.
gmp_lib.free(rp, s1p, s2p, result);
See Also