Click or drag to resize
gmp_libmpn_cnd_swap Method
If cnd is non-zero, swaps the contents of the areas {ap, n} and {bp, n}. Otherwise, the areas are left unmodified.

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 void mpn_cnd_swap(
	mp_limb_t cnd,
	mp_ptr ap,
	mp_ptr bp,
	mp_size_t n
)

Parameters

cnd
Type: Math.Gmp.Nativemp_limb_t
Conditonal value: non-zero for true, zero for false.
ap
Type: Math.Gmp.Nativemp_ptr
The first operand integer.
bp
Type: Math.Gmp.Nativemp_ptr
The second operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of ap and bp.
Remarks

Implemented using logical operations on the limbs, with the same memory accesses independent of the value of cnd.

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

// Exchange ab and bp.
gmp_lib.mpn_cnd_swap(1, ap, bp, ap.Size);

// Assert result of operation.
Assert.IsTrue(ap.SequenceEqual(a1p));
Assert.IsTrue(bp.SequenceEqual(b1p));

// Release unmanaged memory.
gmp_lib.free(ap, bp, a1p, b1p);
See Also