From f950dfb9ab292bc2a1ac34cbc30e6d883bc7ebea Mon Sep 17 00:00:00 2001 From: vlefevre Date: Wed, 18 Feb 2004 10:51:13 +0000 Subject: Ported bug fix / test of mpfr_set_f to the 2.0 branch. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/mpfr-2-0-2-branch@2762 280ebfd0-de03-0410-8827-d642c229c3f4 --- set_f.c | 17 ++++++++++------- tests/tset_f.c | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/set_f.c b/set_f.c index 647ddaafa..e32980b36 100644 --- a/set_f.c +++ b/set_f.c @@ -34,22 +34,25 @@ mpfr_set_f (mpfr_ptr y, mpf_srcptr x, mp_rnd_t rnd_mode) int inexact, carry = 0; TMP_DECL(marker); + sx = ABS(SIZ(x)); /* number of limbs of the mantissa of x */ + + if (sx == 0) /* x is zero */ + { + MPFR_CLEAR_FLAGS (y); + MPFR_SET_ZERO(y); + MPFR_SET_POS(y); + return 0; /* 0 is exact */ + } + if (SIZ(x) * MPFR_SIGN(y) < 0) MPFR_CHANGE_SIGN (y); MPFR_CLEAR_FLAGS (y); - sx = ABS(SIZ(x)); /* number of limbs of the mantissa of x */ sy = 1 + (MPFR_PREC(y) - 1) / BITS_PER_MP_LIMB; my = MPFR_MANT(y); mx = PTR(x); - if (sx == 0) /* x is zero */ - { - MPFR_SET_ZERO(y); - return 0; /* 0 is exact */ - } - count_leading_zeros(cnt, mx[sx - 1]); if (sy <= sx) /* we may have to round even when sy = sx */ diff --git a/tests/tset_f.c b/tests/tset_f.c index 7e8ae4031..42bff6309 100644 --- a/tests/tset_f.c +++ b/tests/tset_f.c @@ -98,13 +98,19 @@ main (void) mpf_set_ui (y, 0); for(r = 0 ; r < 4 ; r++) { - inexact = mpfr_set_f(x, y, r); - if (MPFR_NOTZERO(x) || MPFR_SIGN(x) < 0 || inexact) - { - printf("mpfr_set_f(x,0) failed for %s\n", - mpfr_print_rnd_mode(r)); - exit(1); - } + int i; + for (i = -1; i <= 1; i++) + { + if (i) + mpfr_set_si (x, i, GMP_RNDN); + inexact = mpfr_set_f (x, y, r); + if (!MPFR_IS_ZERO(x) || MPFR_SIGN(x) <= 0 || inexact) + { + printf ("mpfr_set_f(x,0) failed for %s, i = %d\n", + mpfr_print_rnd_mode (r), i); + exit (1); + } + } } /* coverage test */ -- cgit v1.2.1