Click or drag to resize
gmp_libmpn_neg Method
Perform the negation of {sp, n}, and write the result to {rp, n}.

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_neg(
	mp_ptr rp,
	mp_ptr sp,
	mp_size_t n
)

Parameters

rp
Type: Math.Gmp.Nativemp_ptr
The result integer.
sp
Type: Math.Gmp.Nativemp_ptr
The operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of sp and rp.

Return Value

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

This is equivalent to calling mpn_sub_n with a n-limb zero minuend and passing {sp, n} as subtrahend.

Examples
// Create multi-precision operands, and expected result.
mp_ptr sp = new mp_ptr(new uint[] { 0xffffffff, 0xffffffff });
mp_ptr rp = new mp_ptr(new uint[2]);
mp_ptr result = new mp_ptr(new uint[] { 0x0000001, 0x00000000 });

// Set rp = -sp.
mp_limb_t borrow = gmp_lib.mpn_neg(rp, sp, sp.Size);

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

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