diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-09-24 11:15:45 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-09-24 11:15:45 +0000 |
commit | 293ee1f1ce17cd866063bd139070e235c981961d (patch) | |
tree | 62cb0b1ff849ba2e7b4a1c3d4676d9552d27d29d /get_ui.c | |
parent | fbabb2bdac9be26018a509efabc9bfe6b1217527 (diff) | |
download | mpfr-293ee1f1ce17cd866063bd139070e235c981961d.tar.gz |
now use mpfr_rint()
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2988 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'get_ui.c')
-rw-r--r-- | get_ui.c | 28 |
1 files changed, 2 insertions, 26 deletions
@@ -34,35 +34,11 @@ mpfr_get_ui (mpfr_srcptr f, mp_rnd_t rnd) if (!mpfr_fits_ulong_p (f, rnd) || MPFR_IS_ZERO(f)) return (unsigned long) 0; - /* now 0 <= f and either f <= ULONG_MAX or - round(f, prec(ULONG_MAX), rnd) <= ULONG_MAX */ - - exp = MPFR_EXP(f); - if (exp <= 0) /* 0 < f < 1 */ - { - /* return 0 for round to zero or -infinity, - 1 for round to +infinity, - and for round to nearest: - 0 if f <= 1/2 (even rule) - 1 otherwise */ - return (rnd == GMP_RNDZ || rnd == GMP_RNDD) ? 0 - : ((rnd == GMP_RNDU) ? 1 - : (mpfr_cmp_ui_2exp (f, 1, -1) <= 0 ? 0 : 1)); - } - - /* now exp > 0 */ - - /* determine prec of unsigned long */ - for (s = ULONG_MAX, prec = 0; s != 0; s /= 2, prec ++); - - /* since f < 2^EXP(f), we need at most min(prec,EXP(f)) bits */ - prec = (exp < prec) ? exp : prec; - if (prec < MPFR_PREC_MIN) - prec = MPFR_PREC_MIN; + for (s = ULONG_MAX, prec = 0; s != 0; s >>= 1, prec ++); /* first round to prec bits */ mpfr_init2 (x, prec); - mpfr_set (x, f, rnd); + mpfr_rint (x, f, rnd); /* now the result is in the most significant limb of x */ exp = MPFR_GET_EXP (x); /* since |x| >= 1, exp >= 1 */ |