Add {s1p, n} and {s2p, n}, and write the n 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)
Syntaxpublic static mp_limb_t mpn_add_n(
mp_ptr rp,
mp_ptr s1p,
mp_ptr s2p,
mp_size_t n
)
Public Shared Function mpn_add_n (
rp As mp_ptr,
s1p As mp_ptr,
s2p As mp_ptr,
n As mp_size_t
) As mp_limb_t
public:
static mp_limb_t mpn_add_n(
mp_ptr^ rp,
mp_ptr^ s1p,
mp_ptr^ s2p,
mp_size_t n
)
static member mpn_add_n :
rp : mp_ptr *
s1p : mp_ptr *
s2p : mp_ptr *
n : mp_size_t -> mp_limb_t
Parameters
- rp
- Type: Math.Gmp.Nativemp_ptr
The result integer. - s1p
- Type: Math.Gmp.Nativemp_ptr
The first operand integer. - s2p
- Type: Math.Gmp.Nativemp_ptr
The second operand integer. - n
- Type: Math.Gmp.Nativemp_size_t
The number of limbs in s1p and s2p.
Return Value
Type:
mp_limb_tReturn carry, either
0 or
1.
Remarks
This is the lowest-level function for addition.
It is the preferred function for addition, since it is written in assembly for most CPUs.
For addition of a variable to itself (i.e., s1p equals s2p)
use mpn_lshift(mp_ptr, mp_ptr, mp_size_t, UInt32) with a count of 1 for optimal speed.
Examples
mp_ptr s1p = new mp_ptr(new uint[] { 0xffffffff, 0xffffffff });
mp_ptr s2p = new mp_ptr(new uint[] { 0x00000001, 0x00000000 });
mp_ptr rp = new mp_ptr(new uint[2]);
mp_ptr result = new mp_ptr(new uint[] { 0x00000000, 0x00000000 });
mp_limb_t carry = gmp_lib.mpn_add_n(rp, s1p, s2p, rp.Size);
Assert.IsTrue(carry == 1);
Assert.IsTrue(rp.SequenceEqual(result));
gmp_lib.free(rp, s1p, s2p, result);
Dim s1p As New mp_ptr(New UInteger() { &HffffffffUI, &HffffffffUI})
Dim s2p As New mp_ptr(New UInteger() { &H1, &H0})
Dim rp As New mp_ptr(New UInteger(1) { })
Dim result As New mp_ptr(New UInteger() { &H0, &H0})
Dim carry As mp_limb_t = gmp_lib.mpn_add_n(rp, s1p, s2p, rp.Size)
Assert.IsTrue(carry = 1)
Assert.IsTrue(rp.SequenceEqual(result))
gmp_lib.free(rp, s1p, s2p, result)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also