summaryrefslogtreecommitdiff
path: root/set_d.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-03 10:24:47 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-10-03 10:24:47 +0000
commit2285134178bf9486303e0fa09cf2cde2aff7ac78 (patch)
tree2bf2ae2055e3b64f55dd7d7995353590f9e09a8f /set_d.c
parent0318c063720642f479a27493237fdca1085b515c (diff)
downloadmpfr-2285134178bf9486303e0fa09cf2cde2aff7ac78.tar.gz
fixed bug in mpfr_set_d on 64-bit machines
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1213 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'set_d.c')
-rw-r--r--set_d.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/set_d.c b/set_d.c
index e554f4010..3f505a5d7 100644
--- a/set_d.c
+++ b/set_d.c
@@ -254,7 +254,7 @@ mpfr_set_d (r, d, rnd_mode)
{
int signd, sizer, sizetmp;
unsigned int cnt;
- mpfr_ptr tmp;
+ mpfr_ptr tmp;
TMP_DECL(marker);
TMP_MARK(marker);
@@ -278,28 +278,23 @@ mpfr_set_d (r, d, rnd_mode)
return;
}
- sizer = (MPFR_PREC(r)-1)/BITS_PER_MP_LIMB + 1;
+ sizer = (MPFR_PREC(r) - 1) / BITS_PER_MP_LIMB + 1;
- if (sizer < MPFR_LIMBS_PER_DOUBLE)
- {
- tmp = (mpfr_ptr) TMP_ALLOC(sizeof(mpfr_t));
- MPFR_MANT(tmp) = TMP_ALLOC(MPFR_LIMBS_PER_DOUBLE * BYTES_PER_MP_LIMB);
- MPFR_PREC(tmp) = 53;
- MPFR_SIZE(tmp) = MPFR_LIMBS_PER_DOUBLE;
- sizetmp = MPFR_LIMBS_PER_DOUBLE;
- }
- else
- {
- tmp = r;
- sizetmp = sizer;
- }
+ /* warning: don't use tmp=r here, even if sizer >= MPFR_LIMBS_PER_DOUBLE,
+ since PREC(r) may be different from PREC(tmp), and then both variables
+ would have same precision in the mpfr_set4 call below. */
+ tmp = (mpfr_ptr) TMP_ALLOC(sizeof(mpfr_t));
+ MPFR_MANT(tmp) = TMP_ALLOC(MPFR_LIMBS_PER_DOUBLE * BYTES_PER_MP_LIMB);
+ MPFR_PREC(tmp) = 53;
+ MPFR_SIZE(tmp) = MPFR_LIMBS_PER_DOUBLE;
+ sizetmp = MPFR_LIMBS_PER_DOUBLE;
signd = (d < 0) ? -1 : 1;
d = ABS (d);
MPFR_EXP(tmp) = __mpfr_extract_double (MPFR_MANT(tmp) + sizetmp -
MPFR_LIMBS_PER_DOUBLE, d, 1);
-
+
if (sizetmp > MPFR_LIMBS_PER_DOUBLE)
MPN_ZERO(MPFR_MANT(tmp), sizetmp - MPFR_LIMBS_PER_DOUBLE);