summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2022-05-29 12:08:19 +0200
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2022-05-29 12:08:19 +0200
commit55887d0f6365a8b80c22e021a4bc244b40f1039a (patch)
tree2a1a0b59258a5348cd80224e9ed956fad0350fe6
parent31cb34bc1679d7f018273f9639ad924f132e9ef1 (diff)
downloadgmp-55887d0f6365a8b80c22e021a4bc244b40f1039a.tar.gz
mini-gmp/mini-mpq.c (mpq_helper_2exp): New helper function.
-rw-r--r--mini-gmp/mini-mpq.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/mini-gmp/mini-mpq.c b/mini-gmp/mini-mpq.c
index 096332bcf..58ce37f1d 100644
--- a/mini-gmp/mini-mpq.c
+++ b/mini-gmp/mini-mpq.c
@@ -5,7 +5,7 @@
Acknowledgment: special thanks to Bradley Lucier for his comments
to the preliminary version of this code.
-Copyright 2018-2020 Free Software Foundation, Inc.
+Copyright 2018-2022 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -390,22 +390,25 @@ mpq_mul (mpq_t r, const mpq_t a, const mpq_t b)
mpq_clear (t);
}
+static void
+mpq_helper_2exp (mpz_t rn, mpz_t rd, const mpz_t qn, const mpz_t qd, mp_bitcnt_t e)
+{
+ mp_bitcnt_t z = mpz_scan1 (qd, 0);
+ z = GMP_MIN (z, e);
+ mpz_mul_2exp (rn, qn, e - z);
+ mpz_tdiv_q_2exp (rd, qd, z);
+}
+
void
mpq_div_2exp (mpq_t r, const mpq_t q, mp_bitcnt_t e)
{
- mp_bitcnt_t z = mpz_scan1 (mpq_numref (q), 0);
- z = GMP_MIN (z, e);
- mpz_mul_2exp (mpq_denref (r), mpq_denref (q), e - z);
- mpz_tdiv_q_2exp (mpq_numref (r), mpq_numref (q), z);
+ mpq_helper_2exp (mpq_denref (r), mpq_numref (r), mpq_denref (q), mpq_numref (q), e);
}
void
mpq_mul_2exp (mpq_t r, const mpq_t q, mp_bitcnt_t e)
{
- mp_bitcnt_t z = mpz_scan1 (mpq_denref (q), 0);
- z = GMP_MIN (z, e);
- mpz_mul_2exp (mpq_numref (r), mpq_numref (q), e - z);
- mpz_tdiv_q_2exp (mpq_denref (r), mpq_denref (q), z);
+ mpq_helper_2exp (mpq_numref (r), mpq_denref (r), mpq_numref (q), mpq_denref (q), e);
}
void