gmp_libmpn_divrem_1 Method |
Namespace: Math.Gmp.Native
public static mp_limb_t mpn_divrem_1( mp_ptr r1p, mp_size_t qxn, mp_ptr s2p, mp_size_t s2n, mp_limb_t s3limb )
The integer quotient is written to {r1p + qxn, s2n} and in addition qxn fraction limbs are developed and written to {r1p, qxn}. Either or both s2n and qxn can be zero. For most usages, qxn will be zero.
mpn_divmod_1(mp_ptr, mp_ptr, mp_size_t, mp_limb_t) exists for upward source compatibility and is simply a macro calling mpn_divrem_1(mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_limb_t) with a qxn of 0.
The areas at r1p and s2p have to be identical or completely separate, not partially overlapping.
// Create multi-precision operands, and expected result. mp_ptr s2p = new mp_ptr(new uint[] { 0xffffffff, 0x0000ffff }); mp_ptr r1p = new mp_ptr(new uint[2]); mp_ptr result = new mp_ptr(new uint[] { 0x435e50d7, 0x00000d79 }); // Set r1p = s2p / 19. mp_limb_t remainder = gmp_lib.mpn_divrem_1(r1p, 0, s2p, s2p.Size, 0x13); // Assert result of operation. Assert.IsTrue(remainder == 10); Assert.IsTrue(r1p.SequenceEqual(result)); // Release unmanaged memory. gmp_lib.free(r1p, s2p, result);