summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-18 10:51:13 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-18 10:51:13 +0000
commitf950dfb9ab292bc2a1ac34cbc30e6d883bc7ebea (patch)
treef7c88dd1b8a4cd5d784e7ebd7f3a05d079b4ffdc
parentdaa8cfec822ba54527100d1f66a1f8d474eecbfb (diff)
downloadmpfr-f950dfb9ab292bc2a1ac34cbc30e6d883bc7ebea.tar.gz
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
-rw-r--r--set_f.c17
-rw-r--r--tests/tset_f.c20
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 */