diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2014-02-21 19:28:25 +0100 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2014-02-21 19:28:25 +0100 |
commit | 64833fc455fd70188d10b8db27526a99b94619bf (patch) | |
tree | 9ffebfc52682d01a0deca75174311fabb77bbbf3 /mini-gmp | |
parent | 570765cfc250ebe8f95b76362ee411d16fa78ede (diff) | |
download | gmp-64833fc455fd70188d10b8db27526a99b94619bf.tar.gz |
mini-gmp: New function mpn_sqrtrem.
Diffstat (limited to 'mini-gmp')
-rw-r--r-- | mini-gmp/mini-gmp.c | 21 | ||||
-rw-r--r-- | mini-gmp/mini-gmp.h | 1 |
2 files changed, 22 insertions, 0 deletions
diff --git a/mini-gmp/mini-gmp.c b/mini-gmp/mini-gmp.c index f75f87510..6b98fdbd0 100644 --- a/mini-gmp/mini-gmp.c +++ b/mini-gmp/mini-gmp.c @@ -3285,6 +3285,27 @@ mpn_perfect_square_p (mp_srcptr p, mp_size_t n) assert (p [n-1] != 0); return mpz_root (NULL, mpz_roinit_n (t, p, n), 2); } + +mp_size_t +mpn_sqrtrem (mp_ptr sp, mp_ptr rp, mp_srcptr p, mp_size_t n) +{ + mpz_t s, r, u; + mp_size_t res; + + assert (n > 0); + assert (p [n-1] != 0); + + mpz_init (r); + mpz_init (s); + mpz_rootrem (s, r, mpz_roinit_n (u, p, n), 2); + mpn_copyd (sp, s->_mp_d, s->_mp_size); + mpz_clear (s); + res = r->_mp_size; + if (rp) + mpn_copyd (rp, r->_mp_d, res); + mpz_clear (r); + return res; +} /* Combinatorics */ diff --git a/mini-gmp/mini-gmp.h b/mini-gmp/mini-gmp.h index d4054cfd2..cce3dc857 100644 --- a/mini-gmp/mini-gmp.h +++ b/mini-gmp/mini-gmp.h @@ -99,6 +99,7 @@ mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t); void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t); void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t); int mpn_perfect_square_p (mp_srcptr, mp_size_t); +mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t); mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int); |