diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-09-24 14:13:20 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-09-24 14:13:20 +0000 |
commit | 60c3767464b629370f8baf53a198ca13adffc0c1 (patch) | |
tree | 22797c03ba6bfe62ab3e5dfc6682b2fc25e3e037 | |
parent | 5f1352cbc12235100e4b9a3e5d11ef5267ad56d6 (diff) | |
download | mpfr-60c3767464b629370f8baf53a198ca13adffc0c1.tar.gz |
Fixed bugs (like those in mpfr_get_ui).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2991 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | get_si.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -39,14 +39,21 @@ mpfr_get_si (mpfr_srcptr f, mp_rnd_t rnd) /* first round to prec bits */ mpfr_init2 (x, prec); - mpfr_set (x, f, rnd); - - /* now the result is in the most significant limb of x */ - exp = MPFR_GET_EXP (x); /* since |x| >= 1, exp >= 1 */ - n = MPFR_LIMB_SIZE(x); - s = MPFR_MANT(x)[n - 1] >> (BITS_PER_MP_LIMB - exp); + mpfr_rint (x, f, rnd); + + /* warning: if x=0, taking its exponent is illegal */ + if (MPFR_IS_ZERO(x)) + s = 0; + else + { + /* now the result is in the most significant limb of x */ + exp = MPFR_GET_EXP (x); /* since |x| >= 1, exp >= 1 */ + n = MPFR_LIMB_SIZE(x); + s = MPFR_MANT(x)[n - 1] >> (BITS_PER_MP_LIMB - exp); + s *= MPFR_SIGN(f); + } mpfr_clear (x); - return MPFR_SIGN(f) * s; + return s; } |