Click or drag to resize
gmp_libmpn_addmul_1 Method
Multiply {s1p, n} and s2limb, and add the n least significant limbs of the product to {rp, n} and write 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_addmul_1(
	mp_ptr rp,
	mp_ptr s1p,
	mp_size_t n,
	mp_limb_t s2limb
)

Parameters

rp
Type: Math.Gmp.Nativemp_ptr
The result integer.
s1p
Type: Math.Gmp.Nativemp_ptr
The first operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The number of limbs in s1p.
s2limb
Type: Math.Gmp.Nativemp_limb_t
The second operand integer.

Return Value

Type: mp_limb_t
Return the most significant limb of the product, plus carry-out from the addition.
Remarks

{s1p, n} and {rp, n} are allowed to overlap provided rps1p.

This is a low-level function that is a building block for general multiplication as well as other operations in GMP. 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 rp = new mp_ptr(new uint[] { 0x00000002, 0x00000000 });
mp_ptr result = new mp_ptr(new uint[] { 0x00000000, 0x00000000 });

// Set rp += s1 * 2.
mp_limb_t carry = gmp_lib.mpn_addmul_1(rp, s1p, s1p.Size, 2);

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

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