diff options
author | Kevin Ryde <user42@zip.com.au> | 2000-10-24 02:01:52 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2000-10-24 02:01:52 +0200 |
commit | c80ef6347eb6b7346ef27cbf33eec21363362152 (patch) | |
tree | 528ceea7f7b050e8856dfff802f715ca56846bf4 /mpq/div.c | |
parent | 3cda1002de93124d5a1e127c6400779c9581825d (diff) | |
download | gmp-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/div.c')
-rw-r--r-- | mpq/div.c | 32 |
1 files changed, 14 insertions, 18 deletions
@@ -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_div (mpq_ptr quot, mpq_srcptr op1, mpq_srcptr op2) @@ -53,27 +63,13 @@ mpq_div (quot, op1, op2) mpz_gcd (gcd1, &(op1->_mp_num), &(op2->_mp_num)); mpz_gcd (gcd2, &(op2->_mp_den), &(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_den), gcd2); - else - mpz_set (tmp2, &(op2->_mp_den)); + DIV_OR_SET (tmp1, &(op1->_mp_num), gcd1); + DIV_OR_SET (tmp2, &(op2->_mp_den), gcd2); mpz_mul (numtmp, tmp1, tmp2); - if (gcd1->_mp_size > 1 || gcd1->_mp_d[0] != 1) - mpz_divexact (tmp1, &(op2->_mp_num), gcd1); - else - mpz_set (tmp1, &(op2->_mp_num)); - - 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_num), gcd1); + DIV_OR_SET (tmp2, &(op1->_mp_den), gcd2); mpz_mul (&(quot->_mp_den), tmp1, tmp2); |