gmp_libmpn_cnd_sub_n Method |
If
cnd is non-zero, it produces the same result as a regular
mpn_sub_n, and if
cnd is zero, it copies {
s1p,
n} to the result area and returns zero.
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_cnd_sub_n(
mp_limb_t cnd,
mp_ptr rp,
mp_ptr s1p,
mp_ptr s2p,
mp_size_t n
)
Public Shared Function mpn_cnd_sub_n (
cnd As mp_limb_t,
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_cnd_sub_n(
mp_limb_t cnd,
mp_ptr^ rp,
mp_ptr^ s1p,
mp_ptr^ s2p,
mp_size_t n
)
static member mpn_cnd_sub_n :
cnd : mp_limb_t *
rp : mp_ptr *
s1p : mp_ptr *
s2p : mp_ptr *
n : mp_size_t -> mp_limb_t
Parameters
- cnd
- Type: Math.Gmp.Nativemp_limb_t
Conditonal value: non-zero for true, zero for false. - 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 of s1p and s2p.
Return Value
Type:
mp_limb_tIf
cnd is non-zero, return borrow, either 0 or 1, and if
cnd is zero, return 0.
Remarks
This function does conditional addition.
If cnd is non-zero, it produces the same result as a regular mpn_sub_n,
and if cnd is zero, it copies {s1p, n} to the result area and returns zero.
The functions is designed to have timing and memory access patterns depending only
on size and location of the data areas, but independent of the condition cnd.
Like for mpn_sub_n, on most machines, the timing will also be independent
of the actual limb values.
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[] { 0xfffffffe, 0xffffffff });
mp_limb_t borrow = gmp_lib.mpn_cnd_sub_n(1, rp, s1p, s2p, rp.Size);
Assert.IsTrue(borrow == 0);
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() { &HfffffffeUI, &HffffffffUI})
Dim borrow As mp_limb_t = gmp_lib.mpn_cnd_sub_n(1, rp, s1p, s2p, rp.Size)
Assert.IsTrue(borrow = 0)
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