Click or drag to resize
gmp_libmpn_sec_add_1 Method
Set R to A + b, where R = {rp, n}, A = {ap, n}, and b is a single limb.

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_sec_add_1(
	mp_ptr rp,
	mp_ptr ap,
	mp_size_t n,
	mp_limb_t b,
	mp_ptr tp
)

Parameters

rp
Type: Math.Gmp.Nativemp_ptr
The result integer.
ap
Type: Math.Gmp.Nativemp_ptr
The first operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of ap and rp.
b
Type: Math.Gmp.Nativemp_limb_t
The second operand integer.
tp
Type: Math.Gmp.Nativemp_ptr
The scratch operand integer.

Return Value

Type: mp_limb_t
Returns carry, either 0 or 1.
Remarks

This function takes O(N) time, unlike the leaky functions mpn_add_1 which is O(1) on average. It requires scratch space of mpn_sec_add_1_itch(n) limbs, to be passed in the tp parameter. The scratch space requirements are guaranteed to be at most n limbs, and increase monotonously in the operand size.

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

// Create scratch space.
mp_size_t size = gmp_lib.mpn_sec_add_1_itch(ap.Size);
mp_ptr tp = new mp_ptr(size);

// Set rp = ap + 1.
mp_limb_t carry = gmp_lib.mpn_sec_add_1(rp, ap, ap.Size, 1, tp);

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

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