summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--set_q.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/set_q.c b/set_q.c
index 0dc42c091..21e0025c4 100644
--- a/set_q.c
+++ b/set_q.c
@@ -26,7 +26,7 @@ MA 02111-1307, USA. */
#include "longlong.h"
/* set f to the rational q */
-void
+int
#if __STDC__
mpfr_set_q (mpfr_ptr f, mpq_srcptr q, mp_rnd_t rnd)
#else
@@ -36,30 +36,27 @@ mpfr_set_q (f, q, rnd)
mp_rnd_t rnd;
#endif
{
- int sign;
mpz_srcptr num, den;
- unsigned int prec;
- mpfr_t n,d;
+ mpfr_t n, d;
+ int inexact;
MPFR_CLEAR_FLAGS(f);
num = mpq_numref (q);
- sign = mpz_cmp_ui (num, 0);
- if (sign == 0)
+ if (mpz_cmp_ui (num, 0) == 0)
{
MPFR_SET_ZERO(f);
- return;
+ return 0;
}
den = mpq_denref(q);
- prec = MPFR_PREC(f);
mpfr_init2 (n, mpz_sizeinbase(num, 2));
mpfr_set_z (n, num, GMP_RNDZ); /* result is exact */
- mpfr_init2(d, mpz_sizeinbase(den, 2));
- mpfr_set_z(d, den, GMP_RNDZ); /* result is exact */
- MPFR_PREC(f) = prec;
- mpfr_div(f, n, d, rnd);
- mpfr_clear(n);
- mpfr_clear(d);
+ mpfr_init2 (d, mpz_sizeinbase(den, 2));
+ mpfr_set_z (d, den, GMP_RNDZ); /* result is exact */
+ inexact = mpfr_div (f, n, d, rnd);
+ mpfr_clear (n);
+ mpfr_clear (d);
+ MPFR_RET(inexact);
}