summaryrefslogtreecommitdiff
path: root/mpq/mul.c
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2000-10-24 02:01:52 +0200
committerKevin Ryde <user42@zip.com.au>2000-10-24 02:01:52 +0200
commitc80ef6347eb6b7346ef27cbf33eec21363362152 (patch)
tree528ceea7f7b050e8856dfff802f715ca56846bf4 /mpq/mul.c
parent3cda1002de93124d5a1e127c6400779c9581825d (diff)
downloadgmp-c80ef6347eb6b7346ef27cbf33eec21363362152.tar.gz
* gmp-impl.h (MPZ_EQUAL_1_P): New macro.
* mpq/mul.c, mpq/div.c: Use it, and a new DIV_OR_SET.
Diffstat (limited to 'mpq/mul.c')
-rw-r--r--mpq/mul.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/mpq/mul.c b/mpq/mul.c
index 4c17e2b00..0419f5cfd 100644
--- a/mpq/mul.c
+++ b/mpq/mul.c
@@ -22,6 +22,16 @@ MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
+
+#define DIV_OR_SET(q,a,d) \
+ do { \
+ if (MPZ_EQUAL_1_P (d)) \
+ mpz_set (q, a); \
+ else \
+ mpz_divexact (q, a, d); \
+ } while (0)
+
+
void
#if __STDC__
mpq_mul (mpq_ptr prod, mpq_srcptr op1, mpq_srcptr op2)
@@ -48,27 +58,13 @@ mpq_mul (prod, op1, op2)
mpz_gcd (gcd1, &(op1->_mp_num), &(op2->_mp_den));
mpz_gcd (gcd2, &(op2->_mp_num), &(op1->_mp_den));
- if (gcd1->_mp_size > 1 || gcd1->_mp_d[0] != 1)
- mpz_divexact (tmp1, &(op1->_mp_num), gcd1);
- else
- mpz_set (tmp1, &(op1->_mp_num));
-
- if (gcd2->_mp_size > 1 || gcd2->_mp_d[0] != 1)
- mpz_divexact (tmp2, &(op2->_mp_num), gcd2);
- else
- mpz_set (tmp2, &(op2->_mp_num));
+ DIV_OR_SET (tmp1, &(op1->_mp_num), gcd1);
+ DIV_OR_SET (tmp2, &(op2->_mp_num), gcd2);
mpz_mul (&(prod->_mp_num), tmp1, tmp2);
- if (gcd1->_mp_size > 1 || gcd1->_mp_d[0] != 1)
- mpz_divexact (tmp1, &(op2->_mp_den), gcd1);
- else
- mpz_set (tmp1, &(op2->_mp_den));
-
- if (gcd2->_mp_size > 1 || gcd2->_mp_d[0] != 1)
- mpz_divexact (tmp2, &(op1->_mp_den), gcd2);
- else
- mpz_set (tmp2, &(op1->_mp_den));
+ DIV_OR_SET (tmp1, &(op2->_mp_den), gcd1);
+ DIV_OR_SET (tmp2, &(op1->_mp_den), gcd2);
mpz_mul (&(prod->_mp_den), tmp1, tmp2);