From 55887d0f6365a8b80c22e021a4bc244b40f1039a Mon Sep 17 00:00:00 2001 From: Marco Bodrato Date: Sun, 29 May 2022 12:08:19 +0200 Subject: mini-gmp/mini-mpq.c (mpq_helper_2exp): New helper function. --- mini-gmp/mini-mpq.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'mini-gmp') 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 -- cgit v1.2.1